我有格式的RSA私钥PEM,是否有直接的方式从.NET读取并实例化RSACryptoServiceProvider解密用相应的公钥加密的数据?
我正在研究一些创建X509certificate和公钥/私钥对的代码.公钥被添加到证书中,并将其发送给签署它的CA.
然后通过System.Security.Cryptography.X509Certificates.X509Certificate2类访问返回的证书.现在,我想使用此证书启动与其他客户端的安全连接.因此我使用SslStream类.要启动SSL握手,我使用以下方法:
server.AssociatedSslStream.AuthenticateAsServer(
MyCertificate, // Client Certificate
true, // Require Certificate from connecting Peer
SslProtocols.Tls, // Use TLS 1.0
false // check Certificate revocation
);
Run Code Online (Sandbox Code Playgroud)
此方法要求私钥与证书关联.当然,CA返回的证书不包含私钥.但它作为.key文件存储在硬盘上.X509Certificate2类有一个名为PrivateKey的属性,我想将私钥与证书关联,但我找不到设置此属性的方法.
有没有办法可以将私钥与.net X509类关联起来?