【问题标题】:Import BouncyCastle X509Certificate + Private Key (RSA) into Windows Certificate Store将 BouncyCastle X509Certificate + 私钥 (RSA) 导入 Windows 证书存储
【发布时间】:2016-02-17 14:58:08
【问题描述】:

我已经尝试了所有方法,通过 .NET X509Certificate2 + RSACryptoServiceProvider 实例导入基于 BouncyCastle 的 X509Certificate 实例和关联的私钥 (RsaPrivateCrtKeyParameters),并将其保存到证书存储中(.NET 的 X509Store,My/CurrentUser) .

在证书存储 MMC 管理单元中,似乎有一个与证书关联的私钥,并且我已经验证在磁盘上的适当位置创建了一个新的密钥容器,但是当我尝试导出证书时,我收到可怕的“注意:找不到关联的私钥。只能导出证书”消息。

如果我运行 certutil -user -repairstore my THUMBPRINT,我会收到以下错误:

错误:证书公钥与存储的密钥集不匹配

从它吐出的其他信息中,我可以清楚地看到公钥不同,并且算法参数在证书公钥上等于“05 00”,而不是在容器公钥上。

事实上,我不知道有容器公钥的概念,所以我现在很困惑。有没有人有一些工作代码可以做到这一点?

【问题讨论】:

  • 不确定您的代码是什么样子,但我的(从 Bouncy Castle 导出为 .pfx 文件,然后通过 BCL 类导入商店)可以完美运行。私钥和证书的合并是在 Bouncy Castle 端进行的,而不是在 BCL 中。

标签: c# x509certificate bouncycastle


【解决方案1】:

我在 Cabadam 的回答中找到了解决方案: https://social.msdn.microsoft.com/Forums/vstudio/en-US/ad01b2eb-1890-431a-86ae-e5da0e02b5b0/cryptographicexception-key-does-not-exist-when-attempting-to-connect-to-remote-service

RSACryptoServiceProvider tempRcsp = (RSACryptoServiceProvider)DotNetUtilities.ToRSA((RsaPrivateCrtKeyParameters)keyPair.Private);
  RSACryptoServiceProvider rcsp = new RSACryptoServiceProvider(new CspParameters(1, "Microsoft Strong Cryptographic Provider", new Guid().ToString(), new CryptoKeySecurity(), null));
  rcsp.ImportCspBlob(tempRcsp.ExportCspBlob(true));
  dotnetCertificate2.PrivateKey = rcsp;
// Save the certificate to the X509Store

【讨论】:

    猜你喜欢
    • 2019-12-06
    • 2011-11-09
    • 2013-05-30
    • 2011-05-11
    • 2013-03-18
    • 1970-01-01
    • 2013-12-04
    • 2011-12-16
    • 1970-01-01
    相关资源
    最近更新 更多