92

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?

U880D
  • 8,601
  • 6
  • 24
  • 40
simpatico
  • 10,709
  • 20
  • 81
  • 126

1 Answers1

203

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"
reddtoric
  • 568
  • 1
  • 6
  • 13
Jcs
  • 13,279
  • 5
  • 53
  • 70
  • 2
    keytool error: java.security.UnrecoverableKeyException: Cannot recover key I get the message above.. Any suggestions? – Foo Jun 21 '15 at 13:16
  • Hard to say. Maybe your keystore file has been tampered with. Any other enclosed exception which could give us an idea of the cause? – Jcs Jun 24 '15 at 08:48
  • 4
    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_ALIAS – Vic Torious Jan 11 '17 at 12:08
  • 1
    I was able to run keytool on windows 10 by running it in [bash/windows subsystem for linux](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide) – Jon May 15 '17 at 20:00
  • 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. – WesternGun Jul 18 '17 at 12:57
  • Not working "keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect" – Maher Abuthraa Aug 01 '18 at 04:53
  • 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? – android developer Feb 13 '23 at 13:17