3 Simple Steps to Install Certificate in Java

3 Simple Steps to Install Certificate in Java

In java all the certificates should be installed in the below file:

C:\Program Files\Java\jre1.8.0_111\lib\security\cacerts

Path and version vary based on your own system configuration, path where you installed and version what you installed.
You can find a file named “cacerts” which is the one will have all the certificate details installed on this particular jre.

Step 1: Path of the certificate storage

As I mentioned

lib\security\cacerts

is the path where we need to install our certificates.

 

 

Step 2: Verifying the certificate

Verify the certificate whether it is already installed or not using the below command:

keytool -v -list -keystore PATH_OF_CACERTS >> Existing_Certificates.txt

Here,

keytool -v -list -keystore C:\Program Files\Java\jre1.8.0_111\lib\security\cacerts >> Existing_Certificates.txt

 

[Here I am exporting all the console output to Existing_Certificates.txt file just for backup and reference].

 

 

Step 3: Install your certificate

Sample cert name: xxx.yyy.zzz.cer

install – keytool -import -alias javadomain -keystore cacerts -file PATH_OF_THE_CERTIFICATE_WHICH_NEEDS_TO_INSTALLED

Eg:

install – keytool -import -alias javadomain -keystore cacerts -file c:\certificates\xxx.yyy.zzz.cer

Now you have successfully installed the certificates. You can verify whether your certificate is exist or not by doing the step 2 again.

 

If you do not have access to the security\cacerts path, then you can do,

You can install certificate in some path, say d:\certificates\ then you can import.

 

Create a file named cacerts inside d:\certificates first,

“C:\Program Files\Java\jdk1.8.0_45\bin\keytool.exe” -importcert -alias javadomain -file d:\certificates\xxx.yyy.zzz.cer -keystore cacerts

 

“C:\Program Files\Java\jdk1.8.0_45\bin\keytool.exe” -list -keystore d:\certificates\cacerts

 

In Eclipse in the Args on (Run As -> Configuration)

-Djavax.net.ssl.keyStore=d:\certificates\cacerts

Or you can add in your code this way,

System.setProperty(“javax.net.ssl.keyStore”, “d:/certificates/cacerts”);
System.setProperty(“javax.net.ssl.trustStorePassword”, “changeit”);

Default password is changeit, if the password is different correct it above.

 

 

Feel free to write your comments/suggestions in the below comments section.

Leave a Reply