KB Article #67384

Split PKCS12 (.p12) file into two pem keys (public and private)

Problem


How to split a PKCS12 (.p12) file into two pem keys (public and private) using openssl?


Resolution


1. To extract the private key, use the following command:



./openssl pkcs12 -nocerts -in mycert.p12 -out userkey.pem



where mycert.p12 is the full path to the certificate (if not in the current folder), and userkey.pem is the output name of the private key file that will be created.



2. To extract the public key, use the following command:



./openssl pkcs12 -clcerts -nokeys -in mycert.p12 -out usercert.pem



where mycert.p12 is the full path to the certificate (if not in the current folder), and usercert.pem is the output name of the public key file that will be created.