31

I know that this is unsafe, but is there any easy way to pass passphrase to the jarsigner.exe:

jrsigner.exe -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ...

Enter Passphrase for keystore:

I am running it in batch file.

2 Answers 2

67
+50

Well, why do you not simply use the corresponding parameters?

jarsigner -keystore my-keystore -storetype jceks -storepass "test" -keypass "test" my-archive.jar xander

Broken down into separate lines for better readability (but you have to put all parameters on one line, of course):

jarsigner
  -keystore my-keystore    # keystore path name
  -storetype jceks         # keystore type (whatever format yours is in)
  -storepass "test"        # keystore password
  -keypass "test"          # private key password
  my-archive.jar           # JAR path name
  xander                   # key name (alias)

Update: Please note with regard to passwords that

  • enclosing passwords in double or single quotes is optional if the passwords contain no special characters.
  • on the Windows command line you have to use double quotes enclosing passwords with special characters such as space. I am mentioning that because someone previously edited my answer and used single quotes which would simply fail on the Windows command line.
  • on UNIX-like systems like Linux or also in the Windows Git Bash or Cygwin you can use both double or single quotes, but with double quotes beware of shell expansion.
6
  • 1
    even if -keypass my_coolpass is in command line, it still asks for it Commented Feb 9, 2017 at 11:44
  • 1
    You wrote the error message reads: "Enter Passphrase for keystore" So you are not missing the password for the private key but the one for the keystore itself. Next time just read my answer more carefully, please. I documented both passwords. The command line help for the tool also describes it.
    – kriegaex
    Commented Feb 9, 2017 at 12:58
  • Tons of thanx, dear @kriegaex Commented Feb 9, 2017 at 13:44
  • 2
    You have given me the gift of Time. Thank you Sir! Commented Mar 21, 2018 at 23:31
  • This is exactly why people like me love SO. I wish I could upvote this multiple times :)
    – Atul
    Commented Feb 18, 2020 at 15:16
0

My scenario was the Google plugin for Unity stopped passing the password to the jarsigner.

In the Sign() method, on file

\Assets\GooglePlayPlugins\com.google.android.appbundle\Editor\Scripts\Internal\BuildTools\JarSigner.cs

Change this:

var arguments = string.Format(
                "-J-Duser.language=en -keystore {0} {1} {2}",
                CommandLine.QuotePath(_keystoreName),
                CommandLine.QuotePath(zipFilePath),
                CommandLine.QuotePath(_keyaliasName));

to this:

var arguments = string.Format(
                "-J-Duser.language=en " +
                "-keystore  {0} " + // keystore path name
                "-storepass {1} " + // keystore password
                "-keypass   {2} " + // private key password
                "{3} " +            // JAR/ZIP/Bundle path name
                "{4} ",             // key name (alias)
                CommandLine.QuotePath(_keystoreName),
                _keystorePass,
                _keyaliasPass,
                CommandLine.QuotePath(zipFilePath),
                CommandLine.QuotePath(_keyaliasName));

Not the answer you're looking for? Browse other questions tagged or ask your own question.