Convert PEM to DER
openssl x509 -outform der -in certificate.pem -out certificate.der
Convert PEM to P7B
openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer
Convert PEM to PFX
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt
Convert DER to PEM
openssl x509 -inform der -in certificate.cer -out certificate.pem
Convert P7B to PEM
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
Convert P7B to PFX
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer
Convert PFX to PEM
openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes
The other type of questions I received is related to moving keys from "keytool" keystore files to "OpenSSL" key files. Since "keytool" does not support key exporting function, I wrote a Java program to dump keys out of the keystore file. In this chapter, I recorded the following testing scenarios to find a way to move keys from "keytool" keystore files to "OpenSSL" key files:
Using "keytool" to generate a private and public key pair.
Using "keytool" to export the self-signed certificate from PrivateKeyEntry.
Using "keytool" to display details of a certificate.
Using "OpenSSL" to view certificate exported by "keytool".
Writing "DumpKey.java" to dump key pair out of "keytool" keystore files.
Using "OpenSSL" to convert dumped key pair from binary to Base64 encoding.
Using "OpenSSL" to view key pair dumped and converted from "keytool" keystore files.