Thursday, January 17, 2013

Store certificate in key store

When it is using trusted certificate in JAVA, it needs to be stored in JAVA key store.

JAVA default key store is %JAVA_HOME/jre/lib/security/cacerts

Using following command you can create a specific key store.

keytool -keystore keystore_name -storepass changeit -file \export\home\root.cer -import -alias alias_name -trustcacerts

Then use the following JAVA code to use the created key store.

System.setProperty("javax.net.ssl.trustStore", "./keystore_name ");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");