Search code examples
javakeytooljks

Keytool creates key with wrong password


The problem I'm having with Jetty not liking my Java Keystore boils down to this, I think:

Generate a new keystore (I've included the password for clarity):

keytool -keystore mark.jks -alias markkey -genkey -keyalg RSA
Enter keystore password: password
Re-enter new password: password
What is your first and last name?
  [Unknown]:  Mark
What is the name of your organizational unit?
  [Unknown]:  MarkProject
What is the name of your organization?
  [Unknown]:  MarkCo
What is the name of your City or Locality?
  [Unknown]:  MarkTown
What is the name of your State or Province?
  [Unknown]:  Markia
What is the two-letter country code for this unit?
  [Unknown]:  UK
Is CN=Mark, OU=MarkProject, O=MarkCo, L=MarkTown, ST=Markia, C=UK correct?
  [no]:  yes
Enter key password for <markkey> password
    (RETURN if same as keystore password):  
Re-enter new password: password

So I should have a keystore with password password, containing a key with password password -- correct? (BTW: if I press RETURN for same as keystore password the results are the same.)

Try to change the passwords:

keytool -keypasswd -new changeit -keystore mark.jks -storepass changeit -alias markkey -keypass password
keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect

How can this be? What have I done wrong or misunderstood, please?


Solution

  • Your session transcript says:

    keytool -keystore mark.jks -alias markkey -genkey -keyalg RSA
    Enter keystore password: password
    Re-enter new password: password
    

    But then you do

    keytool .... -keystore mark.jks -storepass changeit ....
                                               ^^^^^^^^
    

    It will be this incorrect keystore password that it's complaining about.