Re: X509Certificate2 and en/decryption



<b.fokke@xxxxxxxxx> wrote in message
// Retrieve RSA CSP containing public key
RSACryptoServiceProvider rsa =
(RSACryptoServiceProvider)certificate.PublicKey.Key;
byte[] encrypted = rsa.Encrypt(toEncrypt , false);
// Retrieve RSA CSP containing private key
RSACryptoServiceProvider rsa =
(RSACryptoServiceProvider)certificate.PrivateKey;
byte[] decrypted = rsa.Encrypt(encrypted , false);

You're calling the Encrypt method twice; you should first call the Encrypt
method of the PublicKey or PrivateKey (it doesn't make a difference) and
then call the Decrypt method of the PrivateKey object.

Regards,
Pieter Philippaerts


.