Monday, August 1, 2022

How to Extract Private Key From a Certificate using OpenSSL

Import new Cert PEM file into local SSL Cert store. Make sure you mark the key as exportable. Next, export the certificate as PFX and make sure to export the key along with the cert.

Take the file you exported (e.g. certname.pfx) and copy it to a system where you have OpenSSL installed. Note: the *.pfx file is in PKCS#12 format and includes both the certificate and the private key.

Run the following commands to extract the key:

Run the following command to export the private key: openssl pkcs12 -in certname.pfx -nocerts -out certame.key.pem -nodes

Optionally, run the following command to remove the passphrase from the private key: openssl rsa -in certname.pem -out certname.key