Programming Tutorials

Signing a jar file example

By: Fanny Ong in Java Tutorials on 2007-10-14  

Suppose you have a JAR file named "bundle.jar" and you'd like to sign it using the private key of the user whose keystore alias is "jane" in the keystore named "mystore" in the "working" directory. Suppose the keystore password is "myspass" and the password for jane's private key is "j638klm". You can use the following to sign the JAR file and name the signed JAR file "sbundle.jar":

    jarsigner -keystore /working/mystore -storepass myspass
      -keypass j638klm -signedjar sbundle.jar bundle.jar jane 

Note that there is no -sigfile specified in the command above, so the generated .SF and .DSA files to be placed in the signed JAR file will have default names based on the alias name. That is, they will be named JANE.SF and JANE.DSA.

If you want to be prompted for the store password and the private key password, you could shorten the above command to

    jarsigner -keystore /working/mystore
      -signedjar sbundle.jar bundle.jar jane 

If the keystore to be used is the default keystore (the one named ".keystore" in your home directory), you don't need to specify a keystore, as in:

    jarsigner -signedjar sbundle.jar bundle.jar jane 

Finally, if you want the signed JAR file to simply overwrite the input JAR file (bundle.jar), you don't need to specify a -signedjar option:

    jarsigner bundle.jar jane 





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)