使用证书调用服务:错误 - "Keyset does not exist"

Calling service using certificate :Error - "Keyset does not exist"

我目前正在尝试访问第三方提供的服务。他们向我们颁发了 PKCS 格式的证书。证书安装在本地计算机 - 受信任的根目录中。

我们的应用程序在 运行 时间找到此证书并将其发送到由第 3 方托管的身份验证 URL,在那里对它进行身份验证并颁发 SAML 令牌。然后用于调用执行我们所需功能的实际服务。

当我 运行 我的应用程序通过开发机器 [Windows 7] 中的服务引用使用此服务时,一切正常。

现在的痛点是,由于我们有一个 Citrix 环境,我们会在其中进行测试,所以我们得到一个错误

Exception in METHOD: SOAP security negotiation with "Service URL" for target failed. Inner Exception: System.Security.Cryptography.CryptographicException: Keyset does not exist.

任何人都可以帮助我解决这个问题,因为我无法在本地重现它并且它只发生在服务器 OS 中,我不确定它是权限问题还是某些代码问题。

这个问题可能有两个原因:

  1. 证书没有私钥。
  2. 您的进程运行的用户无权读取私钥。

因为您已经在您的开发环境中设置了它并且 运行,我们假设原因是 2。

如果您还不知道,您需要确定您的进程在测试服务器上运行的用户帐户。然后在测试服务器上打开MMC和add the Certificates snap-in。找到证书,右键单击并选择 All Tasks | Manage Private Keys... 并授予用户读取权限。

阅读更多相关信息:

X509Certificate - Keyset does not exist

CryptographicException 'Keyset does not exist', but only through WCF

Service failure with CryptographicException – Keyset does not exist

Wcf: Keyset does not exist

感谢您提供信息。此问题的根本原因是证书的权限问题。由于证书安装在具有管理员权限的服务器中,因此必须授予所有用户访问证书的权限。