0
votes

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?

1
Nine sorry, I change the path to show the code simpler, I will uopdate this, but this is not the problem, thanks - Julito Avellaneda
Have you tried running the application with administrator privileges? - NineBerry
This in a web site publish on IIS, running with the AppPoolIdentity, others app with the same identity ar working fine - Julito Avellaneda

1 Answers

0
votes

Possible dupe, and has a probable answer:

"An internal error occurred." when loading pfx file with X509Certificate2

In short, in your local environment, it's probably trying to put the cert in your local user store, but that store is not accessible from your web site. It instead needs to be told to go to the machine store.