* @throws KeystoreException
*/
public void changeKeyPassword(String alias, char[] storePassword, char[] keyPassword, char[] newKeyPassword) throws KeystoreException {
ensureLoaded(storePassword);
if(!privateKeys.contains(alias)) {
throw new KeystoreException("No private key entry "+alias+" exists in the keystore "+keystoreName);
}
if(keyPasswords.containsKey(alias)) {
if(!Arrays.equals(keyPasswords.get(alias), keyPassword)) {
throw new KeystoreException("Incorrect password provided for private key entry "+alias);
}
keyPasswords.put(alias, newKeyPassword);
}
PrivateKey key = getPrivateKey(alias, storePassword, keyPassword);
Certificate[] chain = getCertificateChain(alias, storePassword);
try {
keystore.setKeyEntry(alias, key, newKeyPassword, chain);
saveKeystore(storePassword);
log.info("Password changed for private key entry "+alias+" in keystore "+keystoreName+".");
if(keyPasswords.containsKey(alias)) {
storePasswords();
}
} catch(KeyStoreException e) {
throw new KeystoreException("Could not change password for private key entry "+alias, e);
}
}