问题
I changed pass of my keystore:
keytool -list -storetype JCEKS -keystore store.jceks -storepasswd -new secret
here I have 3 entry
passwd = new char[] { 's', 'e', 'c', 'r', 'e', 't' };
fis = new FileInputStream("myKeys.jceks");
ks.load(fis, passwd);
KeyStore.SecretKeyEntry skEntry = (KeyStore.SecretKeyEntry) ks.getEntry(alias, new KeyStore.PasswordProtection(
passwd));
here I got exception:
java.security.UnrecoverableKeyException: Given final block not properly padded
can you help me what is wrong ?
回答1:
May be you changed the password of the key-store but not of the key-entry? Both can be changed individually.
passwdStore = new char[] { 's', 'e', 'c', 'r', 'e', 't' };
passwdEntry = new char[] { 'p', 'a', 's', 's', 'w', '2' };
fis = new FileInputStream("myKeys.jceks");
ks.load(fis, passwdStore);
KeyStore.SecretKeyEntry skEntry = (KeyStore.SecretKeyEntry) ks.getEntry(alias, new KeyStore.PasswordProtection(passwdEntry));
回答2:
Ok I found my mistake. I have to firstly run keypasswd for all entries:
keytool -keypasswd -storetype JCEKS -keystore myKeys.jceks
and then storepasswd:
keytool -storepasswd -storetype JCEKS -keystore myKeys.jceks
for whole keystore.
来源:https://stackoverflow.com/questions/9665801/java-keystore-and-password-changing