Search code examples
javacertificatekeykeytooljks

What is the purpose of a .jks keystore?


I've been asked to create a jks keystore based on a certificate we had created. I've read a bit on the topic, but I'm still confused on a few items:

Is the private key of a certificate supposed to be stored in a .jks keystone?

If yes - where does this get entered in? Using the keytool, it doesn't require one for creating a jks file.

If no - what is the purpose of a jks file? Why would my application need it instead of just reading in a certificate directly? And why does the keytool require a password to create a jks if it just contains a public key?


Solution

  • Is the private key of a certificate supposed to be stored in a .jks keystone?

    Yes, if you own the certificate and it is stored there.

    If yes - where does this get entered in? Using the keytool, it doesn't require one for creating a jks file.

    That's because you can also use it as a truststore, which only contains trusted certificates.

    To get the private key in there you will need to first convert it and its certificate to a PKCS#12 file using openssl, as answered in numerous questions here such as this.

    If no - what is the purpose of a jks file? Why would my application need it instead of just reading in a certificate directly?

    Because your application also needs the private key of the certificate.

    And why does the keytool require a password to create a jks if it just contains a public key?

    A keystore has a password because it is a security-related entity.