Skip to content

Instantly share code, notes, and snippets.

@mdsaleemj
Last active January 21, 2022 07:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdsaleemj/13e46af09d4eaf222761b1577f370448 to your computer and use it in GitHub Desktop.
Save mdsaleemj/13e46af09d4eaf222761b1577f370448 to your computer and use it in GitHub Desktop.
openssl-extract-private-key-from-pfx

Customers sometimes have a need to export a certificate and private key from a Windows computer to separate certificate and key files for use elsewhere. Windows doesn't provide the means to complete this process.

Exporting Certificates from the Windows Certificate Store describes how to export a certificate and private key into a single .pfx file. Follow the procedure below to extract separate certificate and private key files from the .pfx file.

Procedure:

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 command to export the private key: openssl pkcs12 -in certname.pfx -nocerts -out key.pem -nodes

Run the following command to export the certificate: openssl pkcs12 -in certname.pfx -nokeys -out cert.pem

Run the following command to remove the passphrase from the private key: openssl rsa -in key.pem -out server.key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment