SSL – Convert PEM and private key to PKCS#12

For the SSL certificate, Java doesn’t understand PEM format, and it supports JKS or PKCS#12. This article shows you how to use OpenSSL to convert the existing pem file and its private key into a single PKCS#12 or .p12 file.

Solution

Convert cert.pem and private key key.pem into a single cert.p12 file, key in the key-store-password manually for the .p12 file.

Terminal

$ openssl pkcs12 -export -out cert.p12 -in cert.pem -inkey key.pem

Enter Export Password:
Verifying - Enter Export Password:

No password for cert.p12

Terminal

$ openssl pkcs12 -export -out cert.p12 -in cert.pem -inkey key.pem -passout pass: -nokeys

Password 123 for cert.p12

Terminal

$ openssl pkcs12 -export -out cert.p12 -in cert.pem -inkey key.pem -passout pass: 123

More helps.

Terminal

$ openssl pkcs12 --help

References

5 comments on “SSL – Convert PEM and private key to PKCS#12

  1. pem files are OK, but I recive a error

    Could not display example.com.p12
    Reason: Could not parse invalid or corrupted data.

    Reply
  2. Good Day Sir! How do you convert .pem file that also contains the private key to .p12 file?

    Reply
  3. Thanks a lot! This is what I’ve been looking for.

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *