java.security.UnrecoverableKeyException: Cannot recover key
June 28, 2011 11:11:03 Last update: June 28, 2011 11:11:03
This exception occurs when trying to get a private key:
Stack trace:
which was caused by giving a wrong private key password.
The solution is to correct the key password in your code, or change the password in the keystore to match that in your code:
PrivateKey privateKey = (PrivateKey) keyStore.getKey( keyAlias, "private_key_password".toCharArray() );
Stack trace:
Exception in thread "main" java.security.UnrecoverableKeyException: Cannot recover key at sun.security.provider.KeyProtector.recover(KeyProtector.java:311) at sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:121) at sun.security.provider.JavaKeyStore$JKS.engineGetKey(JavaKeyStore.java:38) at java.security.KeyStore.getKey(KeyStore.java:763)
which was caused by giving a wrong private key password.
The solution is to correct the key password in your code, or change the password in the keystore to match that in your code:
keytool -keypasswd -alias mykey -keypass oldpassword -new newpassword