I need to read a p12 file from a disk location, in my local environment all works fine, but when I publish the site to a windows server 2008 I'm getting the following error:
System.Security.Cryptography.CryptographicException: An internal error occurred.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
The code I have is:
var certP12 = new X509Certificate2(
@"C:\temp\file.p12",
"123456",
X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
I already set full permissions to the folder that has the p12 file.
Anyone can help with this?