我有一个问题是解密消息usgin X.509证书.
我使用makecert生成我的证书:
makecert -r -pe -n "CN=MyCertificate" -ss CA -sr CurrentUser -a sha1 -sky signature -cy authority -sv CA.pvk CA.cer
Run Code Online (Sandbox Code Playgroud)
PrivateKey是"mypassword".
我的问题是当我想解密用c#中的先前证书加密的消息时.
我发现这个类http://blog.shutupandcode.net/?p=660,但是在X509Decrypt方法中,PrivateKey一直是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 …