I have been reading about JKS Java keystore, but didn´t find details about the format.

  • The store password is just to verify the integrity of the file?
  • How does the private keys are protected?
  • 1
    The way Java handles keys is obscure and frustrating! – trognanders Nov 16 '16 at 7:01

details about [JKS] format.

This is implemented by sun.security.provider.JavaKeyStore (source in mercurial) but is pretty simple and based on Java's Data{Output,Input}Stream conventions: 4-byte magic number, 4-byte version number, 4-byte count of entries; a variable number of entries each containing 4-byte type, length+(modified)UTF name, 8-byte timestamp, length+encoding+certcount for a privatekey, and type (in practice always X.509)+length+encoding for the/each certificate; and at the end hash of password plus preceding data for integrity check.

The store password is just to verify the integrity of the file?

Yes. The JCA API, and the JKS format, allows each privatekey to be encrypted with a separate password, which can be different from the store password. keytool for example allows you to specify a key password, but defaults it to be the same as the store password. However, some programs cannot cope with differing key and store passwords; in particular, those using the default trustmanager and/or keymanager for SSL/TLS (and thus HTTPS) so in those cases the same password must be used for both store and key(s).

How does the private keys are protected?

Each privatekey is PBE+hash using a 'proprietary' scheme in sun.security.provider.KeyProtector (source in mercurial) and formatted in the file as a PKCS#8 EncryptedPrivateKeyInfo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.