Okay. So I’ve been searching google for days trying to find an answer to this question. I am trying to password protect private keys of a public/private keypair like keytool does. This needs to be used in an environment where keytool is not available and plus, I want to find out how keytool does it. Does anyone know how to do this in Java?
Share
Use password based encryption – it is best for this purpose.
Keytool doesn’t implement it itself. It is implemented in keystore. To be more precise in
java.security.KeyStoreSpi#engineSetKeyEntryandjava.security.KeyStoreSpi#engineGetKeymethods.Keystore type JKS is implemented in
sun.security.provider.JavaKeyStore. Password protection is implemented insun.security.provider.KeyProtector. JKS stores keys in PKCS#8 format, but uses its own algorithm (OID 1.3.6.1.4.1.42.2.17.1.1) with SHA1. It is a kind of PBE. Look at example of open JKS implementation.As Tom suggested below (in his comment) you could look at sun.security.tools.KeyTool class.