OpenSSL certificate conversion cheatsheet

Convert a DER file (.crt .cer .der) to PEM:

[root@ultra ~]# openssl x509 -inform der -in certificate.cer -out certificate.pem

Convert a PEM file to DER file (.crt .cer .der):

[root@ultra ~]# openssl x509 -outform der -in certificate.pem -out certificate.der

Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM:

[root@ultra ~]# openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12):

[root@ultra ~]# openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

Convert PEM to CRT (.CRT file):

[root@ultra ~]# openssl x509 -outform der -in certificate.pem -out certificate.crt

Convert PEM to P7B:

[root@ultra ~]# openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer

Convert PEM to PFX:

[root@ultra ~]# openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

Convert P7B to PEM:

[root@ultra ~]# openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

Convert P7B to PFX:

[root@ultra ~]# openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
[root@ultra ~]# openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer

Convert PFX to PEM:

[root@ultra ~]# openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes

Remove the passphrase on an RSA private key:

[root@ultra ~]# openssl rsa -in key.pem -out keyout.pem

Encrypt a private key using triple DES:

[root@ultra ~]# openssl rsa -in key.pem -des3 -out keyout.pem

Convert a private key from PEM to DER format:

[root@ultra ~]# openssl rsa -in key.pem -outform DER -out keyout.der

Print out the components of a private key to standard output:

[root@ultra ~]# openssl rsa -in key.pem -text -noout

Output the public part of a private key:

[root@ultra ~]# openssl rsa -in key.pem -pubout -out pubkey.pem

Output the public part of a private key in RSAPublicKey format:

[root@ultra ~]# openssl rsa -in key.pem -RSAPublicKey_out -out pubkey.pem

Source: stackoverflow. Edited.