【发布时间】: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.
我已验证以下内容:
- 证书有一个私钥。
- 证书的读取权限授予 IUSR、网络服务、本地服务和 MMC 控制台上的本地用户上下文。证书位于 localMachine - Personal 文件夹中
- 对位于“C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys”的 machinekeys 文件夹授予相同的读取权限。
我已经检查了以下页面上的答案,但绝对没有一个对我有用:
- Stack Overflow User @blowdart's answer
- MSDN Answer
- 其他网站,但这与设置 IIS 和获取证书以在那里工作有关
我在 Visual Studio 中运行应用程序,并且在上面的代码段中,它抛出了试图设置 SignedXml's SigningKey 的异常
我还能做些什么来启动和运行它? (事后我也尝试过证书和文件夹的“所有人”权限——即使抛出了同样的异常)
【问题讨论】:
标签: c# cryptography certificate private-key