Code signing
Java Jarsigner

Jarsigner command examples

3min

The Java jarsigner tool serves the following purposes:

  • Signs Java ARchive (JAR) files.
  • Verifies the signatures and integrity of signed JAR files.

The following sections provide examples of each function:

Sign a Java Archive file

Perform the following steps to ensure that the keys stored on the HSM (that you need for signing) are accessible and sign a Java ARchive (JAR) file:

1

Go to the $JAVA_HOME/bin directory:

Shell

2

Run the following keytool command to list all of the keys on the HSM that the configured identity can access:

Shell


The response should be similar to the following example:

Shell

3

Now that you've confirmed the keys needed for code signing are accessible, run the following command to sign a JAR file by using the HSM-stored keys:

The last field in thefollowing command, JarsignerDemo, must match the alias you specified in the keytool -importcert command in the previous section.

Shell

4

When prompted for the passphrase of the KeyStore, enter the password you specified for the JarsignerDemo KeyStore in the previous section.

If the signing succeeded, the response includes a confirmation message that says: jar signed.

Refer to the Oracle documentation about other flags you can use in the preceding jarsigner command, such as -tsa and -tsacert.

Verify the signature of a signed JAR file

The jarsigner command in the previous section returned a signed JAR file called demo_signed.jar. To verify the signature, perform the following task:

1

Run the following command to verify the signature of that file:

Shell


If the verification succeeded, the response includes a confirmation message saying jar verified.