Can not get key from KeyStore

I've run accross the similar issue. The root of the problem was that I used a different password for the key than for the whole keystore. The code is similar to the one in the JSSE article. It looks like this:

serverKeyStore.load(new FileInputStream("resource/server.jks"), passphrase.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(serverKeyStore);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(serverKeyStore, keyphrase.toCharArray());

I use the keystore pass in the first line and the key pass in the last.


This basically means 2 things,

  1. You had a bad password.
  2. Your keystore is corrupted somehow.

I suspect it's #1. Double check your password. Try if you can list the key in keytool with the same password.