Arbeta med cert och nyckel i OpenSSL

Merge certificate and private key

OpenSSL.exe pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx

Extract Private Key from PFX

The following command will extract the private key from the .pfx file. A new file private-key.pem will be created in current directory.
This command required a password set on the pfx file.

openssl pkcs12 -in myfile.pfx -nocerts -out private-key.pem -nodes
Enter Import Password:

Open the result file (private-key.pem) and copy text between and encluding —–BEGIN PRIVATE KEY—– and —–END CERTIFICATE—– text.

Extract Certificate from PFX

Then extract the certificate file. The following command will extract the certificate from the .pfx file.
You can find the certificate in file named certificate.pem.

openssl pkcs12 -in myfile.pfx -nokeys -out certificate.pem
Enter Import Password:

Open the result file (certificate.pem) and copy text between and encluding —–BEGIN CERTIFICATE—– and —–END CERTIFICATE—– text.
This file may also include the other certificate chain. The first block will be your domain certificate and others will be the chain.
You can copy all the certificates in one file and use it.