Extract certificate and/or key from a PKCS12 file

The PKCS12 format is replacing the old PFX format from Microsoft. This format will allow storage of X.509 private keys and the associated public certificates in a single encrypted file.

So you can extract the key and the certificate in a single common PEM file, you can use this openssl command:

openssl pkcs12 -in myCertificate.pfx -out myCertificateAndMyKey.pem

If you want to extract the key and the certificate independently, you can also use the options nocerts/nokeys along with openssl, to extract only one part:

openssl pkcs12 -in myCertificate.pfx -nocerts -out myCertificate.key
openssl pkcs12 -in myCertificate.pfx -nokeys -out myCertificate.pem