相关疑难解决方法(0)

rsacryptoserviceprovider使用x509证书c#

我正在使用由makecert生成的证书,该证书包含私钥和公钥.java端使用此公钥来加密数据,.net将其解密.

我试图解密Java的加密64位编码字符串并获取错误的数据.

为了看看是否一切都很好.在线端,我试图用公钥加密,然后使用相同的证书与私有解密.我的代码看起来像这样.

X509Certificate2 cert = GetCert(key, StoreName.My, StoreLocation.LocalMachine);
RSACryptoServiceProvider provider =  (RSACryptoServiceProvider)cert.PrivateKey;

RSACryptoServiceProvider publicprovider = (RSACryptoServiceProvider)cert.PublicKey.Key;

if (cert.HasPrivateKey)
    MessageBox.Show("Got private key");

byte[] encrypted = publicprovider.Encrypt(Encoding.UTF8.GetBytes(text), false);
byte[] decryptedBytes = provider.Decrypt(encrypted, false); 
Run Code Online (Sandbox Code Playgroud)

即便在这里我也收到了错误.我错过了什么吗?

证书看起来对公钥和私钥都有效.

.net security cryptography encryption-asymmetric

7
推荐指数
2
解决办法
2万
查看次数