OpenSSL cert conversion

Convert PFX to PEM

openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes

Convert PEM to PFX

 openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt 

Convert P7B to PEM

openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

Convert P7B to PFX

Note: This requires 2 commands

# Step 1
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

# Step 2
openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer
openssl pkcs7 -print_certs -in old.p7b -out new.crt

Convert DER to PEM

openssl x509 -inform der -in certificate.cer -out certificate.pem

Convert DER to CRT

Use the following command to convert a DER encoded certificate into a PEM encoded certificate:

openssl x509 -inform DER -in yourdomain.der -outform PEM -out yourdomain.crt

Use the following command to convert a DER encoded private key into a PEM encoded private key:

openssl rsa -inform DER -in yourdomain_key.der -outform PEM -out yourdomain.key

Convert CER to PEM

openssl x509 -in cert.cer -out cert.pem
Convert PEM to DER

Convert PEM to DER

openssl x509 -outform der -in certificate.pem -out certificate.der

Convert CRT to DER

Use the following command to convert a PEM encoded certificate into a DER encoded certificate:

openssl x509 -inform PEM -in yourdomain.crt -outform DER -out yourdomain.der

Use the following command to convert a PEM encoded private key into a DER encoded private key:

openssl rsa -inform PEM -in yourdomain.key -outform DER -out yourdomain_key.der

Convert PEM to P7B

 openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer 

Convert CRT to PEM

openssl x509 -inform DER -outform PEM -in my_certificate.crt -out my_certificate.pem

PEM format:

openssl rsa -inform PEM -in /tmp/ssl.key

Check to see if your Certificate is in PEM format:

openssl x509 -inform PEM -in /tmp/certificate.crt

Last updated