Are you too constantly looking for the right commands to convert the format of your certificates? In this article, we have compiled all possible conversion scenarios.
List of all possible scenarios for converting the format of your certificates
For converting certificates from one format to another, we will use 2 tools here: OpenSSL and keytool.
Make sure you replace the appropriate file names and extensions according to your use case.
OpenSSL
- Convert a .pem to a .der certificate format
openssl x509 -outform der -in cert.pem -out cert.der
- Convert a DER to a PEM certificate format
openssl x509 -inform DER -in cert.pem -out cert.pem
- Convert a .pem to a .p12 certificate format
openssl pkcs12 -export -out cert.p12 -inkey privatekey.pem -in cert.pem
- Convert a .pem to a .p7b certificate format
openssl crl2pkcs7 -nocrl -certfile cert.pem -out cert.p7b -certfile ca.pem
- Convert a .p7b certificate to a .pem file
openssl pkcs7 -print_certs -in multiple_certificats.p7b -out multiple_certificats.pem
- Convert a .p12 to a .pem certificate format
openssl pkcs12 -in cert.p12 -out cert.pem -nodes
- Convert a .pem to a .cer certificate format
openssl x509 -inform PEM -in cert.pem -outform DER -out cert.cer
- Convert a .pem to a .crt certificate format
openssl x509 -inform PEM -in cert.pem -outform PEM -out cert.crt
Convert a PKCS#12 to a PEM + KEY (PEM)
- Certificate in PEM format
openssl pkcs12 -in cert.p12 -nokeys -clcerts -out cert.pem
- Private key in PEM format (unencrypted)
openssl pkcs12 -in cert.p12 -nocerts -nodes -out key.pem
- Private key in PEM format (encrypted)
openssl pkcs12 -in cert.p12 -nocerts -out key_ciphered.pem
Keytool
- Viewing a JKS file with Keytool
keytool -list -v -keystore keystore.jks
- Convert a JKS file to p12 with Keytool
keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.p12 -srcstoretype jks -deststoretype pkcs12
After any conversion, it is important to keep a backup copy of the original certificate and to check the validity of the new certificate.
Is a conversion scenario missing? Write to us and we’ll be happy to add it to our list of commands.