Jarsigner command examples
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:
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:
Go to the $JAVA_HOME/bin directory:
Run the following keytool command to list all of the keys on the HSM that the configured identity can access:
The response should be similar to the following example:
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.
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.
The jarsigner command in the previous section returned a signed JAR file called demo_signed.jar. To verify the signature, perform the following task:
Run the following command to verify the signature of that file:
If the verification succeeded, the response includes a confirmation message saying jar verified.