Skip to main content

How to sign Java with Code Signing

Summary

Step by step guide on how to sign Java code with a Code Signing certificate.


User-added image

User-added image

Signing Java Code

Before you begin this procedure you must have:

  • an Entrust EV Code Signing Certificate (installed on a token)
  • correctly installed and configured the SafeNet Authentication Client version 10.7, to manage the token
  • the Java Development Kit (JDK) installed ( available from the Oracle Web site )

To sign a .jar file with an EV Code Signing Certificate:

1. Connect your EV code signing token to the USB port of your computer.

2. In any line editor (Notepad, for example), create a text file containing the lines below and save it to your JDK bin folder (for example, C:\Program Files (x86)\Java\jre1.8.0_65\bin) as enToken.cfg.

name=enToken
library=c:\WINDOWS\System32\eTPKCS11.dll


3 .Open a command prompt and move to the JDK bin folder. Run the following command
to obtain the alias name for the private key:

Keytool -list -keystore NONE -storetype PKCS11 -providerclass
sun.security.pkcs11.SunPKCS11 -providerArg ./enToken.cfg


You will be prompted for the keystore password. This is the password that you created when you enrolled for the token.

Example:
User-added image
In the example above, the private key ALIAS is:

le-734f69fa-ba68-4e73-a7ca-027815a944c9

You will use your ALIAS in the next step.

4. To use the certificate to sign JAR file, run the following command:

jarsigner -tsa http://timestamp.entrust.net/rfc3161ts2 -verbose -keystore NONE -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg ./enToken.cfg <your JAR filename> <your private key ALIAS>

Example:
User-added image

5.  To verify that the JAR file has been signed correctly, please use the command below:

jarsigner -verify -verbose <your JAR filename>

Example:
User-added image

Common Errors:

"jarsigner error: java.lang.ClassNotFoundException: sun.security.pkcs11.SunPKCS11"

You will encounter this error when you are using the wrong version of Java Development Kit, specifically when you are using the 64-bit version and require the 32-bit version. To resolve this error, download the 32-bit version of Java Development Kit.

"keytool error: java.security.KeyStoreException: PKCS11 not found"

You will encounter this error if:
- your config file is not properly configured . Check that your config file is pointing to the correct directory (e.g. library=c:\WINDOWS\system32\eTPKCS11.dll).
- your token's device drivers are not installed on your computer . You would have been prompted to install the SafeNet Authentication Client upon picking up and installing your certificate. You may attempt to run the installation again to properly install the Client. If you are unable to install the client please contact support for further assistance.

"jarsigner error: java.lang.RuntimeException: keystore load: load failed"

You will encounter this error if you entered the wrong password.

If you have any questions or concerns please contact the Entrust Certificate Services Support department for further assistance:

Hours of Operation:
Sunday 8:00 PM ET to Friday 8:00 PM ET
North America (toll free): 1-866-267-9297
Outside North America: 1-613-270-2680 (or see the list below)
NOTE: It is very important that international callers dial the UITF format exactly as indicated. Do not dial an extra "1" before the "800" or your call will not be accepted as an UITF toll free call.

Country Number
Australia 0011 - 800-3687-7863
1-800-767-513
Austria 00 - 800-3687-7863
Belgium 00 - 800-3687-7863
Denmark 00 - 800-3687-7863
Finland 990 - 800-3687-7863 (Telecom Finland)
00 - 800-3687-7863 (Finnet)
France 00 - 800-3687-7863
Germany 00 - 800-3687-7863
Hong Kong 001 - 800-3687-7863 (Voice)
002 - 800-3687-7863 (Fax)
Ireland 00 - 800-3687-7863
Israel 014 - 800-3687-7863
Italy 00 - 800-3687-7863
Japan 001 - 800-3687-7863 (KDD)
004 - 800-3687-7863 (ITJ)
0061 - 800-3687-7863 (IDC)
Korea 001 - 800-3687-7863 (Korea Telecom)
002 - 800-3687-7863 (Dacom)
Malaysia 00 - 800-3687-7863
Netherlands 00 - 800-3687-7863
New Zealand 00 - 800-3687-7863
0800-4413101
Norway 00 - 800-3687-7863
Singapore 001 - 800-3687-7863
Spain 00 - 800-3687-7863
Sweden 00 - 800-3687-7863 (Telia)
00 - 800-3687-7863 (Tele2)
Switzerland 00 - 800-3687-7863
Taiwan 00 - 800-3687-7863
United Kingdom 00 - 800-3687-7863
0800 121 6078
+44 (0) 118 953 3088