|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Encrypt datai'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 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. -- Show quoteHide quoteJoe 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 > 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 > > 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. -- Show quoteHide quoteJoe 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 >> > > 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 > >> > > > 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. -- Show quoteHide quoteWilliam Stacey [C# MVP] "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 | > >> > | > > |
Need help with DirectorySearcher FILTER using SID.
Code Access Security for Windows Service The remote server returned an error: (403) Forbidden - even with a valid verisign certificate System.Net.WebException: The remote server returned an error: (404) Not Found. SignedCms.ComputeSignature(CmsSigner) - Keyset does not exist Howto encrypt configuration sections using Enterprise Library ? Assembly Minimum Security Requirements Create X509 certificate in memory *without* makecert Read PEM encoded request certificate in C# hi every one |
|||||||||||||||||||||||