How to pass jarsigner.exe passphrase via commandline?

17,241

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.
Share:
17,241
Stepan Yakovenko
Author by

Stepan Yakovenko

Hello! I'm developing commercial software since age of 16. I am working remotely in international teams since 2011. I have many years of Java/JS/C++/web development experience and also interested in scientific (numerical calculations) work. If you have remote part-time job, please send me an email: [email protected]. Only 100% remote opportunities considered. My resume is available here. #SOreadytohelp

Updated on June 24, 2022

Comments

  • Stepan Yakovenko
    Stepan Yakovenko about 2 years

    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.