0
KeyStore ks = KeyStore.getInstance("PKCS12");
FileInputStream fis = new FileInputStream("/path/to/file.p12");
ks.load(fis, "password".toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, "password".toCharArray());
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), null, null);

This code works fine. But is any possibility to use keystore.jks for that case? For example, I have imported file.p12 into keystore.jks using pkcs12import tool with some alias. Then I use System.setProperty("javax.net.ssl.keyStore" , "C:/Sun/SDK/jdk/jre/lib/security/keystore.jks"); and not write certificate path and password in java code and it take from that keystore.jks file

  • You can also specify a system property for the store type, so you don't need to import to JKS. – erickson Sep 29 '16 at 17:50
  • Possible duplicate of [java - path to trustStore - set property doesnt work?](http://stackoverflow.com/questions/2138574/java-path-to-truststore-set-property-doesnt-work) – Marged Sep 29 '16 at 17:55
  • For system property I use keystore.jks where I have imported many certificates, so I can't use it. – Giorgi Kacadze Sep 29 '16 at 18:15

1 Answers1

0

Yes, it is possible to use a jks keystore to handle the certificates, an example of this can be found here

Community
  • 1
  • 1
Carlos Monroy Nieblas
  • 2,225
  • 2
  • 16
  • 27