Keystore change passwords
Asked Answered
V

8

316

I currently have a keystore, with a particular password that only I should know. I now need to give access to that keystore to someone else, so I would like to either:

1) Change the password, so I can share it with others and let them sign
2) Create a different password and allow them to sign with it.

Is this possible? and - if yes - how?

Viewer answered 22/5, 2010 at 18:22 Comment(0)
G
570

Keystore only has one password. You can change it using keytool:

keytool -storepasswd -keystore my.keystore

To change the key's password:

keytool -keypasswd  -alias <key_name> -keystore my.keystore
Gibbie answered 22/5, 2010 at 20:16 Comment(10)
Great, so the signature of the apk will be the same? Just the password will change? This is what I need too. Chose a bad password, now need to change it.Pieria
Signature won't change, as app is NOT signed with the keystore, but with certificate you keep in keystore.Sessler
keyName is the name of the alias, eg. -alias DipuSeigniory
To remove the password for key, one has to set the same password as for keystore, may be useful for someone ;-)Lolita
Does this apply to .jks too? My keystore is .jks generated by Android StudioWylde
@CodigosTutoriales .jks stands for Java KeyStore, it's the same thing.Subternatural
Found this tool which has a more visual view of of the jks files keystore-explorer.org/index.htmlHagy
And how can we do it programmatically?Bulter
The default password is changeit.Incarnadine
When I try this with a .bks keystore, I get java.io.IOException: Invalid keystore format.Ohmmeter
P
97

[How can I] Change the password, so I can share it with others and let them sign

Using keytool:

keytool -storepasswd -keystore /path/to/keystore
Enter keystore password:  changeit
New keystore password:  new-password
Re-enter new keystore password:  new-password
Poleax answered 22/5, 2010 at 20:18 Comment(6)
does this change the password for the key inside too?Shaeshaef
No. Keystore is one things, passwords (note plural) is another. Use keytool -keypasswd -alias <KeyName> -keystore my.keystore to change password of private key <KeyName>Sessler
after enter keystore pass -changeit it gives error keytool error: java.io.IOException: Keystore was tampered with, or password was incorrectAronarondel
@Dipu, I am getting same error. Have you managed to resolved thatAnathematize
You can verify that the password has changed (if you have doubt) by running the exact same command again. After it prompts for the existing password, if you enter a password that is incorrect, it'll say you entered the wrong password or the file has been tampered with and abort.Schrick
The same for me. "changeit" doesn't work. I assume Android Studio with Gradle generated my keystore for the first time at the moment of the first app build. Does anybody know how to see or to reset the password that was generated by Android studio?Diphthong
S
54

Changing keystore password

$ keytool -storepasswd -keystore keystorename
Enter keystore password:  <old password>
New keystore password: <new password>
Re-enter new keystore password: <new password>

Changing keystore alias password

$ keytool -keypasswd -keystore keystorename -alias aliasname
Enter keystore password:  
New key password for <aliasname>: 
Re-enter new key password for <aliasname>:

Note:

  • keystorenam: name of your keystore (with path if you are in different folder)
  • aliasname: alias name you used when creating (if name has space you can use \)

For example:

$ keytool -keypasswd -keystore keystorename -alias stop\ watch
Sverige answered 20/1, 2014 at 8:9 Comment(5)
It works thank you! One more thing I want to add to change alias name which I wanted and got from a forum. keytool -changealias -keystore my.keystore -alias my_name -destalias my_new_nameGrannias
While changing the alias password I get: UnrecoverableKeyException: Cannot recover key Any suggestions?Madness
@Madness did you ever figure out that issue? I'm getting the same errorCacoepy
Changing keystore alias password what ever you shown doesn't work, It won't ask New key password for <aliasname>. It asks existing password for <aliasname> which is not known in this case.Hellespont
I still get Cannot recover key at the step: New key password for <aliasname>: Any ideas? I just created the key in Android Studio, uploaded, realized I had to update something and now it doesnt work :/Hiragana
L
23

To change the password for a key myalias inside of the keystore mykeyfile:

keytool -keystore mykeyfile -keypasswd -alias myalias
Labarum answered 28/8, 2012 at 18:10 Comment(2)
What is "inside key"?Ulibarri
Sorry for my bad explanation. You can change the password of the keystore or the password of one of the keys you have stored on the keystore. That's what I mean with "inside key".Labarum
D
11

For a full programmatic change (e.g. install program) and no prompting

#!/bin/bash -eu

NEWPASSWORD=${1}
OLDPASSWORD=${2}

keytool -storepasswd -new "${NEWPASSWORD}" \
  -storepass "${OLDPASSWORD}" \
  -keystore /path/to/keystore

Full disclosure: I DO NOT recommend running this command line in a shell, as the old and new passwords will be saved in the shell's history, and visible in console.

Donettedoney answered 6/2, 2019 at 16:12 Comment(0)
G
10

KeyStore Explorer is an open source GUI replacement for the Java command-line utilities keytool and jarsigner. KeyStore Explorer presents their functionality, and more, via an intuitive graphical user interface.

  1. Open an existing KeyStore
  2. Tools -> Set KeyStore password
Guay answered 19/7, 2018 at 8:33 Comment(2)
best solution! Better than writing to the terminal. Using this software - I was able to change the passwords and add new key pairs. Highly recommendBollard
Fantastic little app, worked like a charm!Casmey
H
8

If the keystore contains other key-entries with different password you have to change them also or you can isolate your key to different keystore using below command,

keytool -importkeystore  -srckeystore mystore.jck -destkeystore myotherstore.jks -srcstoretype jceks
-deststoretype jks -srcstorepass mystorepass -deststorepass myotherstorepass -srcalias myserverkey
-destalias myotherserverkey -srckeypass mykeypass -destkeypass myotherkeypass
Hurry answered 10/2, 2014 at 8:49 Comment(0)
A
6

There are so many answers here, but if you're trying to change the jks password on a Mac in Android Studio. Here are the easiest steps I could find

1) Open Terminal and cd to where your .jks is located

2) keytool -storepasswd -new NEWPASSWORD -keystore YOURKEYSTORE.jks

3) enter your current password

Arista answered 1/6, 2016 at 21:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.