Home All Groups Group Topic Archive Search About
Author
24 Nov 2006 10:18 AM
crino
Hi,
i'm trying to encrypt data with a publickey exctracted from certificate

file but i got error!?
this is my code:

using Microsoft.Web.Services3.Security.X509;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;


//exctract the key
X509Certificate2 certp = new X509Certificate2(Server.MapPath(".") +
"\\mycert.cer");
RSACryptoServiceProvider rsa =
(RSACryptoServiceProvider)X509Util.GetKey(cert);


//encrypt data
byte[] enc = rsa.Encrypt(barray, false);  //barray is the byte array of

my data to encrypt


Anyone can help me?
Is quite urgenge :-P


Thanks in advance

Author
24 Nov 2006 4:28 PM
Joe Kaplan
You don't encrypt bulk data with RSA keys.  RSA is for encrypting small
amounts of data, generally other encryption keys used in symmetric
encryption.  Typically, you would want to do something like creating an
enveloped CMS message, as it takes care of these details for you.  Check out
the Pkcs namespace in .NET 2.0.

You also don't say what error you got (which would have been helpful), but
based on your code, it looks like you are going in the wrong direction
anyway.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
Show quoteHide quote
"crino" <cseverini.nospam@gmail.com> wrote in message
news:1164363514.012036.293880@k70g2000cwa.googlegroups.com...
> Hi,
> i'm trying to encrypt data with a publickey exctracted from certificate
>
> file but i got error!?
> this is my code:
>
> using Microsoft.Web.Services3.Security.X509;
> using System.Security.Cryptography.X509Certificates;
> using System.Security.Cryptography;
>
>
> //exctract the key
> X509Certificate2 certp = new X509Certificate2(Server.MapPath(".") +
> "\\mycert.cer");
> RSACryptoServiceProvider rsa =
> (RSACryptoServiceProvider)X509Util.GetKey(cert);
>
>
> //encrypt data
> byte[] enc = rsa.Encrypt(barray, false);  //barray is the byte array of
>
> my data to encrypt
>
>
> Anyone can help me?
> Is quite urgenge :-P
>
>
> Thanks in advance
>
Author
24 Nov 2006 5:38 PM
crino
hi Joe :)
barray is just 1024bit.
Error is 'The key state is not viled' or something like this (i don't
get english message)
Anyway my goal is just encrypt barray (1024bit) with the publickey
extracted from certificate file.
Any idea?


Joe Kaplan ha scritto:

Show quoteHide quote
> You don't encrypt bulk data with RSA keys.  RSA is for encrypting small
> amounts of data, generally other encryption keys used in symmetric
> encryption.  Typically, you would want to do something like creating an
> enveloped CMS message, as it takes care of these details for you.  Check out
> the Pkcs namespace in .NET 2.0.
>
> You also don't say what error you got (which would have been helpful), but
> based on your code, it looks like you are going in the wrong direction
> anyway.
>
> Joe K.
>
> --
> Joe Kaplan-MS MVP Directory Services Programming
> Co-author of "The .NET Developer's Guide to Directory Services Programming"
> http://www.directoryprogramming.net
> --
> "crino" <cseverini.nospam@gmail.com> wrote in message
> news:1164363514.012036.293880@k70g2000cwa.googlegroups.com...
> > Hi,
> > i'm trying to encrypt data with a publickey exctracted from certificate
> >
> > file but i got error!?
> > this is my code:
> >
> > using Microsoft.Web.Services3.Security.X509;
> > using System.Security.Cryptography.X509Certificates;
> > using System.Security.Cryptography;
> >
> >
> > //exctract the key
> > X509Certificate2 certp = new X509Certificate2(Server.MapPath(".") +
> > "\\mycert.cer");
> > RSACryptoServiceProvider rsa =
> > (RSACryptoServiceProvider)X509Util.GetKey(cert);
> >
> >
> > //encrypt data
> > byte[] enc = rsa.Encrypt(barray, false);  //barray is the byte array of
> >
> > my data to encrypt
> >
> >
> > Anyone can help me?
> > Is quite urgenge :-P
> >
> >
> > Thanks in advance
> >
Author
24 Nov 2006 10:34 PM
Joe Kaplan
My recollection of RSA is that you can only encrypt up to key length - 11
bits of data with RSA.  Does it work if you try a smaller set of data?
Otherwise, I don't know.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
Show quoteHide quote
"crino" <cseverini.nospam@gmail.com> wrote in message
news:1164389907.706969.30820@j72g2000cwa.googlegroups.com...
> hi Joe :)
> barray is just 1024bit.
> Error is 'The key state is not viled' or something like this (i don't
> get english message)
> Anyway my goal is just encrypt barray (1024bit) with the publickey
> extracted from certificate file.
> Any idea?
>
>
> Joe Kaplan ha scritto:
>
>> You don't encrypt bulk data with RSA keys.  RSA is for encrypting small
>> amounts of data, generally other encryption keys used in symmetric
>> encryption.  Typically, you would want to do something like creating an
>> enveloped CMS message, as it takes care of these details for you.  Check
>> out
>> the Pkcs namespace in .NET 2.0.
>>
>> You also don't say what error you got (which would have been helpful),
>> but
>> based on your code, it looks like you are going in the wrong direction
>> anyway.
>>
>> Joe K.
>>
>> --
>> Joe Kaplan-MS MVP Directory Services Programming
>> Co-author of "The .NET Developer's Guide to Directory Services
>> Programming"
>> http://www.directoryprogramming.net
>> --
>> "crino" <cseverini.nospam@gmail.com> wrote in message
>> news:1164363514.012036.293880@k70g2000cwa.googlegroups.com...
>> > Hi,
>> > i'm trying to encrypt data with a publickey exctracted from certificate
>> >
>> > file but i got error!?
>> > this is my code:
>> >
>> > using Microsoft.Web.Services3.Security.X509;
>> > using System.Security.Cryptography.X509Certificates;
>> > using System.Security.Cryptography;
>> >
>> >
>> > //exctract the key
>> > X509Certificate2 certp = new X509Certificate2(Server.MapPath(".") +
>> > "\\mycert.cer");
>> > RSACryptoServiceProvider rsa =
>> > (RSACryptoServiceProvider)X509Util.GetKey(cert);
>> >
>> >
>> > //encrypt data
>> > byte[] enc = rsa.Encrypt(barray, false);  //barray is the byte array of
>> >
>> > my data to encrypt
>> >
>> >
>> > Anyone can help me?
>> > Is quite urgenge :-P
>> >
>> >
>> > Thanks in advance
>> >
>
Author
25 Nov 2006 10:10 AM
crino
just 11bit?? (1 byte!)
I'll try anyway i just need to decode this java code:
Signature sigVer = Signature.getInstance("SHA1withRSA");
sigVer.initVerify(publicKey);
sigVer.update(barrayToEncrypt);
result = sigVer.verify(barrayToVerify);

Any idea??


Joe Kaplan ha scritto:

Show quoteHide quote
> My recollection of RSA is that you can only encrypt up to key length - 11
> bits of data with RSA.  Does it work if you try a smaller set of data?
> Otherwise, I don't know.
>
> Joe K.
>
> --
> Joe Kaplan-MS MVP Directory Services Programming
> Co-author of "The .NET Developer's Guide to Directory Services Programming"
> http://www.directoryprogramming.net
> --
> "crino" <cseverini.nospam@gmail.com> wrote in message
> news:1164389907.706969.30820@j72g2000cwa.googlegroups.com...
> > hi Joe :)
> > barray is just 1024bit.
> > Error is 'The key state is not viled' or something like this (i don't
> > get english message)
> > Anyway my goal is just encrypt barray (1024bit) with the publickey
> > extracted from certificate file.
> > Any idea?
> >
> >
> > Joe Kaplan ha scritto:
> >
> >> You don't encrypt bulk data with RSA keys.  RSA is for encrypting small
> >> amounts of data, generally other encryption keys used in symmetric
> >> encryption.  Typically, you would want to do something like creating an
> >> enveloped CMS message, as it takes care of these details for you.  Check
> >> out
> >> the Pkcs namespace in .NET 2.0.
> >>
> >> You also don't say what error you got (which would have been helpful),
> >> but
> >> based on your code, it looks like you are going in the wrong direction
> >> anyway.
> >>
> >> Joe K.
> >>
> >> --
> >> Joe Kaplan-MS MVP Directory Services Programming
> >> Co-author of "The .NET Developer's Guide to Directory Services
> >> Programming"
> >> http://www.directoryprogramming.net
> >> --
> >> "crino" <cseverini.nospam@gmail.com> wrote in message
> >> news:1164363514.012036.293880@k70g2000cwa.googlegroups.com...
> >> > Hi,
> >> > i'm trying to encrypt data with a publickey exctracted from certificate
> >> >
> >> > file but i got error!?
> >> > this is my code:
> >> >
> >> > using Microsoft.Web.Services3.Security.X509;
> >> > using System.Security.Cryptography.X509Certificates;
> >> > using System.Security.Cryptography;
> >> >
> >> >
> >> > //exctract the key
> >> > X509Certificate2 certp = new X509Certificate2(Server.MapPath(".") +
> >> > "\\mycert.cer");
> >> > RSACryptoServiceProvider rsa =
> >> > (RSACryptoServiceProvider)X509Util.GetKey(cert);
> >> >
> >> >
> >> > //encrypt data
> >> > byte[] enc = rsa.Encrypt(barray, false);  //barray is the byte array of
> >> >
> >> > my data to encrypt
> >> >
> >> >
> >> > Anyone can help me?
> >> > Is quite urgenge :-P
> >> >
> >> >
> >> > Thanks in advance
> >> >
> >
Author
25 Nov 2006 4:04 PM
William Stacey [C# MVP]
IIRC, it is a factor of the key size and an enc option set on the keypair.
So for a 1024bit key, it is something less then 128 bytes.  This is plenty
large to encryt a symmetric key, which is what it is normally used for.  The
rest of the session is encrypted with AES (or other) using the symmetric
key.

--
William Stacey [C# MVP]

Show quoteHide quote
"crino" <cseverini.nospam@gmail.com> wrote in message
news:1164449454.808045.241310@j44g2000cwa.googlegroups.com...
| just 11bit?? (1 byte!)
| I'll try anyway i just need to decode this java code:
| Signature sigVer = Signature.getInstance("SHA1withRSA");
| sigVer.initVerify(publicKey);
| sigVer.update(barrayToEncrypt);
| result = sigVer.verify(barrayToVerify);
|
| Any idea??
|
|
| Joe Kaplan ha scritto:
|
| > My recollection of RSA is that you can only encrypt up to key length -
11
| > bits of data with RSA.  Does it work if you try a smaller set of data?
| > Otherwise, I don't know.
| >
| > Joe K.
| >
| > --
| > Joe Kaplan-MS MVP Directory Services Programming
| > Co-author of "The .NET Developer's Guide to Directory Services
Programming"
| > http://www.directoryprogramming.net
| > --
| > "crino" <cseverini.nospam@gmail.com> wrote in message
| > news:1164389907.706969.30820@j72g2000cwa.googlegroups.com...
| > > hi Joe :)
| > > barray is just 1024bit.
| > > Error is 'The key state is not viled' or something like this (i don't
| > > get english message)
| > > Anyway my goal is just encrypt barray (1024bit) with the publickey
| > > extracted from certificate file.
| > > Any idea?
| > >
| > >
| > > Joe Kaplan ha scritto:
| > >
| > >> You don't encrypt bulk data with RSA keys.  RSA is for encrypting
small
| > >> amounts of data, generally other encryption keys used in symmetric
| > >> encryption.  Typically, you would want to do something like creating
an
| > >> enveloped CMS message, as it takes care of these details for you.
Check
| > >> out
| > >> the Pkcs namespace in .NET 2.0.
| > >>
| > >> You also don't say what error you got (which would have been
helpful),
| > >> but
| > >> based on your code, it looks like you are going in the wrong
direction
| > >> anyway.
| > >>
| > >> Joe K.
| > >>
| > >> --
| > >> Joe Kaplan-MS MVP Directory Services Programming
| > >> Co-author of "The .NET Developer's Guide to Directory Services
| > >> Programming"
| > >> http://www.directoryprogramming.net
| > >> --
| > >> "crino" <cseverini.nospam@gmail.com> wrote in message
| > >> news:1164363514.012036.293880@k70g2000cwa.googlegroups.com...
| > >> > Hi,
| > >> > i'm trying to encrypt data with a publickey exctracted from
certificate
| > >> >
| > >> > file but i got error!?
| > >> > this is my code:
| > >> >
| > >> > using Microsoft.Web.Services3.Security.X509;
| > >> > using System.Security.Cryptography.X509Certificates;
| > >> > using System.Security.Cryptography;
| > >> >
| > >> >
| > >> > //exctract the key
| > >> > X509Certificate2 certp = new X509Certificate2(Server.MapPath(".") +
| > >> > "\\mycert.cer");
| > >> > RSACryptoServiceProvider rsa =
| > >> > (RSACryptoServiceProvider)X509Util.GetKey(cert);
| > >> >
| > >> >
| > >> > //encrypt data
| > >> > byte[] enc = rsa.Encrypt(barray, false);  //barray is the byte
array of
| > >> >
| > >> > my data to encrypt
| > >> >
| > >> >
| > >> > Anyone can help me?
| > >> > Is quite urgenge :-P
| > >> >
| > >> >
| > >> > Thanks in advance
| > >> >
| > >
|