java keystore and password changing

我的梦境 提交于 2019-12-11 23:24:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!