Add password to keytool command

TMH picture TMH · Feb 28, 2014 · Viewed 40k times · Source

I've made a .bat file to get the SHA1 of my Android app so I don't need to type the command each time

keytool -list -v -keystore "Path/To/My/Key.jks"

When I run the bat file I get asked for the password. Is it possible to either put the password in the command e.g. something like --password MyPassword, or in the .bat file wait for the Enter your password line, and then send the password? I don't have any experience really with .bat files so I don't know if that's possible to do or not.

I looked at the --help for keytool and the only password flags I could see were for changing the password, not specifying it.

Answer

rxg picture rxg · May 2, 2014

The keytool that ships with the Oracle JDK allows you to specify it on the command line with -storepass, you were doing keytool -help instead of keytool -list -help. (I suppose the Android version is the same.)

C:\>keytool.exe -list -help
keytool -list [OPTION]...

Lists entries in a keystore

Options:

 -rfc                            output in RFC style
 -alias <alias>                  alias name of the entry to process
 -keystore <keystore>            keystore name
 -storepass <arg>                keystore password
 -storetype <storetype>          keystore type
 -providername <providername>    provider name
 -providerclass <providerclass>  provider class name
 -providerarg <arg>              provider argument
 -providerpath <pathlist>        provider classpath
 -v                              verbose output
 -protected                      password through protected mechanism

Use "keytool -help" for all available commands