Extract the public and private keys to pem files via openssl from a certificate
Jan 22, 2021
Have you been goggling and been trying to figure out how I extract this certificate into ***** public and private keys on mac? well, then you’re in luck!
Just use the two commands below:
openssl pkcs12 -in cert.pfx -nokeys -out publiccert.pem -nodesopenssl pkcs12 -in cert.pfx -nocerts -out privatekey.pem -nodes
If the certificate provided has the .p12 extension you can run the same commands to extract the public and private keys into pem files. As the .p12 and .pfx extension have the exact same binary format.
See practical output below, of course, you will need to provide the passphrase provided by the organisation who gave you the certificate.