相关疑难解决方法(0)

X509Certificate构造函数异常

//cert is an EF Entity and 
//    cert.CertificatePKCS12 is a byte[] with the certificate.

var certificate = new X509Certificate(cert.CertificatePKCS12, "SomePassword");
Run Code Online (Sandbox Code Playgroud)

从我们的数据库加载证书时,在我们的登台服务器(Windows 2008 R2/IIS7.5)上,我们遇到以下异常:

System.Security.Cryptography.CryptographicException: An internal error occurred.

   at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
   at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
   at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
Run Code Online (Sandbox Code Playgroud)

注意:此问题不会在本地发生(Windows 7/Casini).

非常感谢任何见解.

.net c# x509certificate

68
推荐指数
4
解决办法
4万
查看次数

CryptographicException未处理:系统找不到指定的文件

我试图接受SSL通信的奥秘,并在这个网站上找到了一个很棒的教程.我试图测试我自己的证书.使用Visual Studio 2012,我只是添加了一个现有文件(我的证书为.pfx格式),然后更改了app.config中的"certificate"和"password"设置.但是,当试图运行它时,我收到一个错误:

CryptographicException未处理:系统找不到指定的文件

然后,我在我的Web服务中尝试了相同的操作.我在那里得到了关于错误的更多细节:

System.Security.Cryptography.CryptographicException: System cannot find specified file.

   at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
   at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName)
   at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags)
   v System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password)
   v TestServer.DataService.LoadSoap() v c:\Users\Administrator\Documents\Visual Studio 2012\Projects\TestServer\TestServer\DataService.asmx.cs:line 48
Run Code Online (Sandbox Code Playgroud)

我已经把这个问题写给了文章的作者,但自从他上次回复是在2012年3月,我不确定,他是否会回复.如果有人可以帮我解决这个问题,我将非常感激.

PS:将证书从.cer导出到.pfx时,我已经更改了导出文件的标题.虽然我怀疑它对这个问题的影响,但我宁愿提一下.

.net c# cryptographicexception x509certificate

56
推荐指数
6
解决办法
4万
查看次数