How to change the alias of a key within a keystore?
Asked Answered
T

1

98

I signed my JWS application MemorizEasy with a key whose alias is:

memofile.reference.emma.jar=/Users/simpatico/.netbeans/6.8/modules/ext/emma.jar

I don't remember why I chose such a long alias. I suspect it was memo only, but in my project settings I have:

jnlp.signjar.alias=memofile.reference.emma.jar=/Users/simpatico/.netbeans/6.8/modules/ext/emma.jar

I'm now updating the application and using maven I need to specify the alias as:

<keystorealias>memofile.reference.emma.jar=/Users/simpatico/.netbeans/6.8/modules/ext/emma.jar
</keystorealias>

Yet that doesn't work. Trying another key with alias mjee it works.

So could I change the alias of the key? If so, how? Otherwise, why wouldn't Maven accept my alias?

Tertial answered 14/8, 2010 at 11:47 Comment(0)
R
213

It is possible to duplicate a key in a keystore with the keyclone command of keytool:

keytool -keyclone -alias "your-very-very-long-alias" -dest "new-alias" -keypass keypass -new new_keypass -keystore /path/to/keystore -storepass storepass

The changealias command changes the alias for an existing entry:

keytool -changealias -alias "your-very-very-long-alias" -destalias "new-alias" -keypass keypass -keystore /path/to/keystore -storepass storepass

For those that want to be prompted to enter password just remove the respective password flags (changealias example):

keytool -changealias -alias "your-very-very-long-alias" -destalias "new-alias" -keystore "/path/to/keystore"
Rosenkranz answered 18/4, 2011 at 18:57 Comment(7)
keytool error: java.security.UnrecoverableKeyException: Cannot recover key I get the message above.. Any suggestions?Displeasure
Hard to say. Maybe your keystore file has been tampered with. Any other enclosed exception which could give us an idea of the cause?Rosenkranz
I found this one to be "easier" because you don't need to enter your passwords directly but will be prompted to do so after the command: keytool -changealias -keystore my_keystore.jks -alias OLD_ALIAS -destalias NEW_ALIASBordeaux
I was able to run keytool on windows 10 by running it in bash/windows subsystem for linuxPreoccupation
java has keytool, no need to refer to bash... you can run it from cmd as far as you have added %JAVA_HOME%\bin to your PATH. Double check with where keytool first.Trochelminth
Not working "keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect"Capua
For an existing keystore file, is it possible to add a new key-alias and key-password for it, in addition to what's there?Kerbstone

© 2022 - 2024 — McMap. All rights reserved.