我正在构build一个由C#.NET进行文档签名的应用程序(win表单)。 我在签名时遇到了错误。 当我在某些计算机(windows 7,windows 10,而不是windows Server)上签署文档时,出现错误:“密钥集未定义”。 所以,有人可以教我或者build议我怎么解决这个问题? 非常感谢! 这是我的代码: // get certficate public X509Certificate2 LoadCertificateFromwindowsStore() { X509Store x509Store = new X509Store(Storename.My,StoreLocation.CurrentUser); try { x509Store.Open(OpenFlags.Readonly | OpenFlags.OpenExistingOnly); X509Certificate2Collection numberCerts = (X509Certificate2Collection)x509Store.Certificates; X509Certificate2Enumerator certEnumerator; if (numberCerts.Count == 1) { certEnumerator = numberCerts.GetEnumerator(); while (certEnumerator.MoveNext()) return certEnumerator.Current; return null; } else if (numberCerts.Count > 1) { X509Certificate2Collection chooseCert = X509Certificate2UI.SelectFromCollection(numberCerts,"Certificates List","Choose your certificate",X509SelectionFlag.SingleSelection);
if (chooseCert.Count == 1) return chooseCert[0]; else return null; } else return null; } catch (CryptographicException e) { Console.Writeline(e.Message); } finally { x509Store.Close(); } return null; }
// using the cert to sign var cert = LoadCertificateFromwindowsStore(); if (cert.HasPrivateKey) // WORKS!!! {
signedXml.SigningKey = cert.PrivateKey; // THROW "keyset does not exist" EXCEPTION ... // get certficate public X509Certificate2 LoadCertificateFromwindowsStore() { X509Store x509Store = new X509Store(Storename.My,X509SelectionFlag.SingleSelection);
if (chooseCert.Count == 1) return chooseCert[0]; else return null; } else return null; } catch (CryptographicException e) { Console.Writeline(e.Message); } finally { x509Store.Close(); } return null; }
// using the cert to sign var cert = LoadCertificateFromwindowsStore(); if (cert.HasPrivateKey) // WORKS!!! {
signedXml.SigningKey = cert.PrivateKey; // THROW "keyset does not exist" EXCEPTION ...
closureswindows资源pipe理器的特定实例
Visual Studio ClickOnce部署是否自动包含必要的.NET框架?
如果wpf应用程序没有响应,然后自动重启
在启动Avaya主动拨号程序时,WPF中的System.AccessViolationException
.NET PInvoke在linux和Mac OS X平台上可用吗?
我已经解决了这个错误。 这很容易。 您选择“平台目标”到x86。
右键点击你的项目 – >属性 – >生成 – >平台目标 – > x86
问候,
总结以上是内存溢出为你收集整理的该键集没有定义全部内容,希望文章能够帮你解决该键集没有定义所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)