【问题标题】:Why getting error The private key is not present in the X.509 certificate为什么会出现错误 X.509 证书中不存在私钥
【发布时间】:2017-10-13 11:26:22
【问题描述】:

我在 C#.NET 中开发了一个 Windows 服务应用程序,现在尝试从这个用 Java 开发的 Windows 服务调用 Web 服务。我的客户向我提供了 .cert 类型的证书和 .pkcs8 类型的私钥。当我尝试调用 Web 服务时,我收到以下错误:

X.509 证书中不存在私钥。

这是我连接 wsdl 的代码:

<clientCredentials>
 <serviceCertificate>
  <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
 </serviceCertificate>
 <clientCertificate storeLocation="CurrentUser" storeName="Root" findValue="176455DB76886FF2BA3C122F8B36322F647CB2FD" x509FindType="FindByThumbprint"/>                     
</clientCredentials>

如果您能在上面建议我了解如何在此证书中包含私钥以从我的代码中调用 Web 服务,我将不胜感激。 提前致谢。

【问题讨论】:

  • 你能给我们看一个调用部分吗?
  • 使用 OpenSSL 将证书及其私钥合并到 PFX 文件中。然后将其导入您的证书存储。目前您只导入了触发错误的证书。

标签: c# ssl x509certificate private-key


【解决方案1】:

问题是因为您将证书导入到 Windows 证书存储区,但没有与私钥关联。您必须将 .cer.pkcs8 文件合并到 PFX 容器中。你也可以使用certutil.exe

certutil -mergepfx path\mycert.cer path\mycert.pfx

注意:重命名您的密钥文件以匹配证书文件名并将扩展名更改为.key。也就是说,这两个文件必须在同一个文件夹中并具有名称,例如:mycert.cermycert.key

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    • 2013-05-05
    相关资源
    最近更新 更多