How to retrieve certificates from a pfx file with c#?

You should be able to get a collection object containing the certs in your .pfx file by using the X509Certificate2Collection class… here’s some C# example code: string certPath = <YOUR PFX FILE PATH>; string certPass = <YOUR PASSWORD>; // Create a collection object and populate it using the PFX file X509Certificate2Collection collection = new X509Certificate2Collection(); … Read more

“An internal error occurred.” when loading pfx file with X509Certificate2

Use the local computer store for the private key: X509Certificate2 cert = new X509Certificate2(“myhost.pfx”, “pass”, X509KeyStorageFlags.MachineKeySet); MachineKeySet is described as “private keys are stored in the local computer store rather than the current user store”. The default with no flags is to place in the user store. Even though you are reading the certificate from … Read more

Convert .pfx to .cer

PFX files are PKCS#12 Personal Information Exchange Syntax Standard bundles. They can include arbitrary number of private keys with accompanying X.509 certificates and a certificate authority chain (set certificates). If you want to extract client certificates, you can use OpenSSL’s PKCS12 tool. openssl pkcs12 -in input.pfx -out mycerts.crt -nokeys -clcerts The command above will output … Read more

Converting pfx to pem using openssl

Another perspective for doing it on Linux… here is how to do it so that the resulting single file contains the decrypted private key so that something like HAProxy can use it without prompting you for passphrase. openssl pkcs12 -in file.pfx -out file.pem -nodes Then you can configure HAProxy to use the file.pem file. This … Read more

Cannot import the keyfile ‘blah.pfx’ – error ‘The keyfile may be password protected’

I was running into this problem as well. I was able to resolve the issue by running sn -i <KeyFile> <ContainerName> (installs key pair into a named container). sn is usually installed as part of a Windows SDK. For example C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\sn.exe. Most likely this location is not on the search … Read more