我的本地电脑商店里有一台x509。我怎么读C#? 我需要使用这种方式获取私钥
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider).cert.PrivateKey()
答案 0 :(得分:1)
这将从“我的”(个人)商店获得证书。
var store = new X509Store(StoreName.My);
store.Open(OpenFlags.ReadOnly);
var certificate = store.Certificates.Single(c => c.Thumbprint == "Whatever-Your-Thumbprint-Is");
store.Close();
此时您将拥有X509Certificate2,您可以从中访问PrivateKey属性。
答案 1 :(得分:0)
public void AddCertificate()
{
if (this.ClientCertificates == null)
{
this.ClientCertificates = new X509CertificateCollection();
}
X509Certificate cert = new X509Certificate(path, pass, X509KeyStorageFlags.MachineKeySet);
this.ClientCertificates.Add(cert);
}