How to add SSL certificate into Java cacerts file and JKS keystore.

How to add SSL certificate into Java cacerts file and JKS keystore.

There are some situation when you want to add certificate into the Java trust store. For example: it is useful in case that you want to trust a self signed certificate. This simple guide shows how to download a certificate and how to add it into Java trust store.

1. Downloading certificate

You can download the certificate in a few ways. Using openssl tool or using browser

1.1. Download SSL certificate using openssl

openssl s_client -showcerts -connect /dev/null|openssl x509 -outform PEM >mycertfile.pem

1.2 Downloading SSL certificate using browser

You can download the certificate using Chrome by going to certificate details and then clicking “Copy to file” button.

2.1 Importing certificate into cacert

Go to the JAVA_HOME\bin directory and run:

keytool -importcert -file mycertfile.pem -keystore cacerts -alias "Alias"

2.2 Importing certificate into jks keystore

keytool -importcert -file mycertfile.pem -keystore keystore.jks -alias "Alias" -storepass <PASSWORD>
At the end… May I ask you for something?

If I helped you solve your problem, please share this post. Thanks to this, I will have the opportunity to reach a wider group of readers. Thank You

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Gerson Recent comment authors
newest oldest most voted
Notify of

Gran aporte, saludos desde colombia