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 better-coding.com:443 /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