Extracting the certificate and keys from a .pfx file #
The .pfx file, which is in a PKCS#12 format, contains the SSL certificate (public keys) and the corresponding private keys. Sometimes, you might have to import the certificate and private keys separately in an unencrypted plain text format to use it on another system. This topic provides instructions on how to convert the .pfx file to .crt and .key files.
# Run the following command to extract the private key:
openssl pkcs12 -in [yourfile.pfx] -nocerts -out [yourkey.key]
#Run the following command to extract the certificate:
openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [youcrt.crt]
#Run the following command to decrypt the private key:
openssl rsa -in [yourkey.key] -out [yourkey-decrypted.key]
Convert .pfx file to .pem format #
There might be instances where you might have to convert the .pfx file into .pem format. Run the following command to convert it into PEM format.
openssl rsa -in [keyfile-encrypted.key] -outform PEM -out [keyfile-encrypted-pem.key]