//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应用程序,我想用它作为客户端来调用SSL SOAP Web服务.我已经获得了一个有效的客户证书foo.pfx
.证书本身有密码.
我在以下位置找到了证书: C:\certs\foo.pfx
要调用Web服务,我需要附加客户端证书.这是代码:
public X509Certificate GetCertificateFromDisk(){
try{
string certPath = ConfigurationManager.AppSettings["MyCertPath"].ToString();
//this evaluates to "c:\\certs\\foo.pfx". So far so good.
X509Certificate myCert = X509Certificate.CreateFromCertFile(certPath);
// exception is raised here! "The specified network password is not correct"
return cert;
}
catch (Exception ex){
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
听起来像尝试读取磁盘的.NET应用程序是个例外.该方法CreateFromCertFile
是一个静态方法,应该创建X509Certificate的新实例.该方法未被重写,并且只有一个参数:路径.
当我检查异常时,我发现:
_COMPlusExceptionCode = -532459699
Source=mscorlib
Run Code Online (Sandbox Code Playgroud)
问题:有没有人知道异常的原因"指定的网络密码不正确"?
我在使用asp webforms构建的SAML服务提供程序项目中使用kentor authservices.
它在开发计算机上运行良好但是当我将它放在生产服务器(Windows 2012 R2,IIS 8)上时,X509Certificates.X509Utils._LoadCertFromFile调用会抛出异常"指定的网络密码不正确".
只是,证书(pfx)没有密码,并且它所处的位置没有以我能看到的任何异常方式保护,但是为了确保我已经尝试过"每个人"临时授予对该文件夹的完全访问权限.
Web配置的相关部分是:
<serviceCertificates>
<add fileName="~/App_Data/M_SSO_SP.pfx"/>
</serviceCertificates>
Run Code Online (Sandbox Code Playgroud)
虽然我不认为它与代码有关,但基于它在开发机器上运行良好 - 可能是证书的服务器端问题?
任何帮助将非常感激.
我有一个控制台应用程序,它从字节数组中加载X509证书,如下所示:
var cert = new X509Certificate2(certificateContent, // byte[]
password, // string
X509KeyStorageFlags.PersistKeySet);
Run Code Online (Sandbox Code Playgroud)
certificateContent
是byte[]
表示pfx文件的内容。该代码对我测试过的许多证书都适用。但是,我正在测试一个证书,该证书导致此行抛出一条CryptographicException
错误消息“指定的网络密码不正确。”,即使提供的密码正确无误。
奇怪的是,我可以在LinqPad中使用相同的代码从具有相同密码的相同pfx文件创建证书,并且可以正常工作。
我已经在调试器的控制台应用程序中检查了呼叫站点,并验证了是否传递了正确的值。
是什么导致该构造函数在控制台应用程序中抛出此异常,但在使用相同数据的LinqPad中却未抛出此异常,并且对于其他证书在两个地方均能正常工作?
更多细节
证书存储在Base64的数据库中。Console应用程序从数据库读取证书,将其从Base64转换为byte [],然后尝试X509Certificate2
如上所述创建对象。
我一直在测试三个证书:
证书1和2在控制台应用程序和LinqPad中均按预期工作。
证书3在LinqPad中可以很好地加载,但是如果我尝试在控制台应用程序中使用它,则会生成上面的错误。
证书2和3之间有两个重要区别。
这些差异之一是否会导致“指定的网络密码不正确”错误?为何所有3个证书在LinqPad中都能正常工作,而在Console应用程序中只有1个抛出错误?