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 both purposes.
Before signing a Java ARchive (JAR) file, ensure that the keys stored on the needed for signing are accessible.
First, navigate to the $JAVA_HOME/bin directory:
Then, run the following keytool command to list all of the keys on the that the configured identity has access to:
When prompted for the KeyStore password in this command, and the commands that follow, enter the identity password configured inside the <CRYPTO-OPR-PASS> tag in the fxpkcs11.cfg file.
The response should be similar to the following:
Now that you know the keys needed for code signing are accessible, run the following command to sign a JAR file using the -stored keys:
You must run the command from the same directory where the example.jar file is stored.
You must copy and paste the value specified in the last field of the preceding jarsigner command, Java Jarsigner:Code Signer:C, from the output you see in the list command in step 2.
If the signing succeeds, the response includes a confirmation message that says, jar signed.
Refer to the Oracle documentation to learn about other flags that you can use in the preceding jarsigner command, such as -tsa and -tsacert.
Run the following command to verify the signature of the signed JAR file output from the previous jarsigner command, demo_signed.jar:
If the verification succeeds, the response includes a confirmation message that says, jar verified.