Main Tutorials

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

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Rey
1 year ago

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

Jeremy
2 years ago

Thank you for your help, it helped a lot

Vitalicus
9 months ago

pem files are OK, but I recive a error

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

gladys
3 years ago

How can do in java code ?

Petter Carranza
3 years ago

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