opensslcommandpkcs#12

Converting PKCS#12 certificate into PEM using OpenSSL


I have OpenSSL x64 on Windows 7 which I downloaded from openssl-for-windows on Google Code. I'm attempting to run:

openssl pkcs12 -export -in "path.p12" -out "newfile.pem" 

but I get an error.

unable to load private key

How do I extract the certificate in PEM from PKCS#12 store using OpenSSL?


Solution

  • Try:

    openssl pkcs12 -in path.p12 -out newfile.crt.pem -clcerts -nokeys
    openssl pkcs12 -in path.p12 -out newfile.key.pem -nocerts -nodes
    

    After that you have:

    To put the certificate and key in the same file without a password, use the following, as an empty password will cause the key to not be exported:

    openssl pkcs12 -in path.p12 -out newfile.pem -nodes
    

    Or, if you want to provide a password for the private key, omit -nodes and input a password:

    openssl pkcs12 -in path.p12 -out newfile.pem
    

    If you need to input the PKCS#12 password directly from the command line (e.g. a script), just add -passin pass:${PASSWORD}:

    openssl pkcs12 -in path.p12 -out newfile.crt.pem -clcerts -nokeys -passin 'pass:P@s5w0rD'