【问题标题】:System.Security.Cryptography.CryptographicException: Keyset does not exist thrown within Visual studioSystem.Security.Cryptography.CryptographicException:在 Visual Studio 中抛出的密钥集不存在
【发布时间】:2014-09-14 17:22:23
【问题描述】:

美好的一天

由于此错误,我在尝试分配私钥时遇到严重问题。

System.Security.Cryptography.CryptographicException: Keyset does not exist

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

var col = store.Certificates.Find(X509FindType.FindBySerialNumber, "00873476DC47C5BB614EA96F2A9CE744A6", false);
var cert = col[0];
var xmlUnSignedSaml = new XmlDocument();
xmlUnSignedSaml.LoadXml(assertion);
xmlUnSignedSaml.PreserveWhitespace = true;
SignedXml signedXml = new SignedXml(xmlUnSignedSaml);

signedXml.SigningKey = cert.PrivateKey; //<<<--- Exception thrown.

我已验证以下内容:

  1. 证书有一个私钥。
  2. 证书的读取权限授予 IUSR、网络服务、本地服务和 MMC 控制台上的本地用户上下文。证书位于 localMachine - Personal 文件夹中
  3. 对位于“C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys”的 machinekeys 文件夹授予相同的读取权限。

我已经检查了以下页面上的答案,但绝对没有一个对我有用:

我在 Visual Studio 中运行应用程序,并且在上面的代码段中,它抛出了试图设置 SignedXml's SigningKey 的异常

我还能做些什么来启动和运行它? (事后我也尝试过证书和文件夹的“所有人”权限——即使抛出了同样的异常)

【问题讨论】:

    标签: c# cryptography certificate private-key


    【解决方案1】:

    我已使用以下步骤解决了我的问题:

    1. 从 Microsoft 下载 WCF_Samples 以访问 FindPrivateKey - 15.5mb in size 解决方案。
    2. 解压压缩文件
    3. 导航到 WCF_Samples\WCF\Setup\FindPrivateKey\CS\FindPrivateKey.sln 并构建它。ctrl+shift+B
    4. Main(string args[])方法中添加如下代码行因为我比较懒,不想通过控制台做:args = new string[] { "My", "LocalMachine", "-t", THUMBPRINT_OBTAINED_IN_MMC, "-a" };
    5. 运行应用程序。我找到了钥匙的路径并导航到它。事实证明,密钥本身的权限未设置

    我更改了密钥本身的权限,我的应用程序开始工作。

    【讨论】:

      猜你喜欢
      • 2012-08-19
      • 2015-08-23
      • 1970-01-01
      • 2017-06-28
      • 2022-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      相关资源
      最近更新 更多