检索生成的CSR的私钥

时间:2011-06-02 05:53:40

标签: c# windows keystore private-key csr

我使用certenroll对象创建CSR。 主键在同一台机器上创建(Ccertificate商店)。

如何检索存储在本地存储中的主键,以便生成CSR。

1 个答案:

答案 0 :(得分:1)

您可以从X509Certificate2.PrivateKey获取私钥。

var store = new X509Store (StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);

var thumbprint = "AA99202885098B541C1ECD09C85351ED084A4A12";
var certificate = store.Certificates.Find (X509FindType.FindByThumbprint, thumbprint, false) [0];

var privateKey = (RSACryptoServiceProvider) certificate.PrivateKey;

此外,X509Certificate提供了以各种格式导出的方法,包括pfx。

相关问题