【发布时间】:2012-04-14 15:43:46
【问题描述】:
//cert is an EF Entity and
// cert.CertificatePKCS12 is a byte[] with the certificate.
var certificate = new X509Certificate(cert.CertificatePKCS12, "SomePassword");
从我们的数据库加载证书时,在我们的暂存服务器(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)
注意:此问题不会在本地发生(Windows 7/Casini)。
非常感谢任何见解。
【问题讨论】:
-
我想问题的根源在于
byte[]data 其中cert.CertificatePKCS12。在没有数据的情况下,只能猜测“发生内部错误”异常的原因。所以我的建议是您创建可在您的环境中使用的测试证书来重现问题,将其保存在文件中并提供链接和密码(如“SomePassword”)以解码证书。在检查数据之后,人们将有更多机会找到原因并提出解决问题的方法。 -
感谢@Oleg 的回复-如果字节数组不好,在Win7 和Win2k8 上不会出错吗?当字节数组写入文件时,它会正确导入。
-
@lukiffer:我的意思不是错误,而是结合了证书、密钥等的一些属性。所以必须分析问题。为了能够重现结果或对其进行分析,需要将 PFX 文件用作字节数组
cert.CertificatePKCS12。 -
@oleg - 哪些属性会导致它在一个操作系统而不是另一个操作系统上失败?出于明显的安全原因,我们无法自行发布证书。
标签: c# .net x509certificate