How to create .pfx file from certificate and private key ?

I need .pfx file to install https on website on IIS.

I have two separate files: certificate (.cer or pem) and private key (.crt) but IIS accepts only .pfx files.

I obviously installed certificate and it is available in certificate manager (mmc) but when I select Certificate Export Wizard I cannot select PFX format (it’s greyed out)

Are there any tools to do that or C# examples of doing that programtically?

Solution 1 :

You will need to use openssl.

openssl pkcs12 -export -out domain.name.pfx -inkey domain.name.key -in domain.name.crt

The key file is just a text file with your private key in it.

If you have a root CA and intermediate certs, then include them as well using multiple -in params

openssl pkcs12 -export -out domain.name.pfx -inkey domain.name.key -in domain.name.crt -in intermediate.crt -in rootca.crt

If you have a bundled crt file that you use, for example, with nginx, you can pass that in along with the cert all in one:

cat domain.name.crt | tee -a domain.name.bundled.crt
cat intermediate.crt | tee -a domain.name.bundled.crt
cat rootca.crt | tee -a domain.name.bundled.crt
openssl pkcs12 -export -out domain.name.pfx \
  -inkey domain.name.key \
  -in domain.name.bundled.crt 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

What do you mean by honeypots ?

Honeypots are attack targets that are set up to see how different attackers attempt exploits. Private firms and governments can utilize the same concept to evaluate their vulnerabilities, which is…
View Answer

Are HTTPS headers encrypted ?

When sending data over HTTPS, I know the content is encrypted, however I hear mixed answers about whether the headers are encrypted, or how much of the header is encrypted.…
View Answer

What do you mean by a botnet ?

A botnet is a collection of internet-connected devices, such as servers, PCs, and mobile phones, that are infected with malware and controlled by it. It’s used to steal data, send…
View Answer