bhavesh1988
bhavesh1988

Reputation: 151

How to acess jvm default KeyStore?

I want to use java key store to save keys and certificates. can anybody share some code to help me with this?

Upvotes: 10

Views: 21572

Answers (2)

Chris White
Chris White

Reputation: 30089

There should be enough example code in the KeyStore Javadocs page to get you started:

As for the 'default' keystore - I'm not sure such a thing exists, normally you either load it explicitly from a file, or you can configure it using the following system properties:

  • javax.net.ssl.keyStore - Keystore location
  • javax.net.ssl.keyStorePassword - Keystore password
  • javax.net.ssl.keyStoreType - Keystore type (JKS, P12 etc)

And similar for the trust store:

  • javax.net.ssl.trustStore
  • javax.net.ssl.trustStorePassword
  • javax.net.ssl.trustStoreType

Upvotes: 6

Bruno
Bruno

Reputation: 122599

There is no default keystore in Java. This is documented in the customization section of the JSSE Reference Guide.

The default trust store is:

jssecacerts, if it exists. Otherwise, cacerts

However, it doesn't mean that these are the stores used by the default SSLContext, since it's also possible to change the default SSLContext (since Java 6) with one that would have been initialised with custom trust managers. (See this answer for more details).

Upvotes: 5

Related Questions