FreeKB - Extract a certificate and private key from a P12 file using OpenSSL on Linux
Extract a certificate and private key from a P12 file using OpenSSL on Linux

Home > Search


Let's say you have a p12 file named foo.p12 that contains both a certificate and a private key. The following OpenSSL command can be used to extract only the certificate from the p12 file. In this example, bar.pem will contain the certificate.

openssl pkcs12 -in foo.p12 -out bar.pem -nokeys

 

bar.pem should contain:

-----BEGIN CERTIFICATE-----
. . .
-----END CERTIFICATE-----

 

This will export the private key.

openssl pkcs12 -in foo.p12 -out bar.key -nodes -nocerts

 

bar.key should contain:

-----BEGIN PRIVATE KEY-----
. . .
-----END PRIVATE KEY-----

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments