//cert is an EF Entity and
// cert.CertificatePKCS12 is a byte[] with the certificate.
var certificate = new X509Certificate(cert.CertificatePKCS12, "SomePassword");
When loading a certificate from our database, on our staging server (Windows 2008 R2/IIS7.5) we get this exception:
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)
NOTE: This issue does not happen locally (Windows 7/Casini).
Any insight is greatly appreciated.
byte[]
data which incert.CertificatePKCS12
. Without having the data one can only guess about the reason of the exception "An internal error occurred". So my suggestion is that you create the test certificate which can be used in your environment to reproduce the problem, save it in the file and provide the link and the password (like "SomePassword") for decoding of the certificate. After examining the data one will have much more chances to find the reson and to suggest a solution of your problem. – Nexuscert.CertificatePKCS12
. – Nexus