I have a problem to decrypt a message usgin X.509 Certificate.
I generate my certificate with makecert with this options:
makecert -r -pe -n "CN=MyCertificate" -ss CA -sr CurrentUser -a sha1 -sky signature -cy authority -sv CA.pvk CA.cer
And the PrivateKey was "mypassword".
My problem is when I want to decrypt a message encrypt with previous certificate in c#.
I found this class http://blog.shutupandcode.net/?p=660, but in the X509Decrypt method allways the PrivateKey is null.
public static byte[] X509Decrypt(byte[] data, string certificateFile, string password) { // load the certificate and decrypt the specified data using (var ss = new System.Security.SecureString()) { foreach (var keyChar in password.ToCharArray()) ss.AppendChar(keyChar); // load the password protected certificate file X509Certificate2 cert = new X509Certificate2(certificateFile, ss); using (RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert.PrivateKey) { return rsa.Decrypt(data, true); } } }
I tried passing the certificate file (.cer)
X509DecryptString(token, @"c:\CA.cer", "mypassword");
And passing the pvk file (.pvk)
X509DecryptString(token, @"c:\CA.pvk", "mypassword");
But allways have that the PrivateKey property is null.
Can anyone guide me to decrypt the message using the pvk file?
Thanks,
Jose