Java Keystore & Truststore - keytool binary
Keystore vs Truststore - Similarities
Usually, the keystore and truststore:
- are used when a Java application needs to communicate over SSL/TLS
- are password-protected files that sit on the same file system as our running application. The default format used for these files is JKS until Java 8. Since Java 9, though, the default keystore format is PKCS12. The biggest difference between JKS and PKCS12 is that JKS is a format specific to Java, while PKCS12 is a standardized and language-neutral way of storing encrypted private keys and certificates
Keystore vs Truststore - Differences
Keystore |
|
---|---|
Truststore |
|
Keystore vs Truststore - SLL/TLS Handshake
Let's say we have a client that wants to communicate with a server over SSL/TLS
The server will look up the associated key from its keystore and present the public key and certificate to the client.
The client, then looks up the associated certificate in our truststore. If the certificate or Certificate Authorities presented by the server is not in our truststore, we’ll get an SSLHandshakeException
and the connection won’t be set up successfully.
Interacting With Keystore and/or Truststore
We can interact with the keystore and/or truststore with either:
- Java programmatically
- command-line keytool
Default Keystore and Truststore
Setting Keystore and/or Truststore to be used in Java App
Subpages
Code Examples
, multiple selections available,