hudi
hudi

Reputation: 16525

java keystore and password changing

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 ?

Upvotes: 0

Views: 6991

Answers (2)

hudi
hudi

Reputation: 16525

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.

Upvotes: 2

Robert
Robert

Reputation: 42575

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));

Upvotes: 2

Related Questions