【发布时间】:2016-12-07 20:38:55
【问题描述】:
我的本地计算机商店中有一台 x509。我如何在 C# 中阅读? 我需要用这种方式获取私钥
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider).cert.PrivateKey()
【问题讨论】:
标签: c# rsa x509certificate2
我的本地计算机商店中有一台 x509。我如何在 C# 中阅读? 我需要用这种方式获取私钥
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider).cert.PrivateKey()
【问题讨论】:
标签: c# rsa x509certificate2
这将为您从“我的”(个人)商店获取证书。
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 属性。
【讨论】:
certificates 变量上使用Find 来查找您的确切证书。
public void AddCertificate()
{
if (this.ClientCertificates == null)
{
this.ClientCertificates = new X509CertificateCollection();
}
X509Certificate cert = new X509Certificate(path, pass, X509KeyStorageFlags.MachineKeySet);
this.ClientCertificates.Add(cert);
}
【讨论】: