What Is a Java Code Signing Certificate and How Do You Use It?

Summarize this article with AI:

Table of Contents

A Java code signing certificate lets a developer sign a JAR file with a private key. Java users can then see who published the code and whether anyone changed it. You sign with the JDK's jarsigner tool and a keystore. We ran every command in this guide on JDK 21 and show the real output.

Definition: A Java code signing certificate is an X.509 certificate with the code signing key usage. Its private key signs JAR files, and its public certificate lets others check the signature.

How Does Java Code Signing Work?

The signer hashes every file in the JAR and records the hashes in the manifest. A signature file then signs that manifest with the certificate's private key. Anyone holding the certificate can recompute the hashes and compare them. A single changed byte breaks the match.

After we signed our test JAR, unzip -l showed three entries in META-INF. They were the manifest, a .SF signature file, and a .RSA file that carries the certificate.

How Do You Create a Signing Key and Sign a JAR File?

Make a key pair in a keystore with keytool, then sign with jarsigner. A test key is enough to learn the flow. The steps below used a self-signed certificate. For a public release, the key pair would come from a certificate authority instead.

  1. Build the JAR with jar cfm app.jar m.txt -C classes ..
  2. Create the key with keytool -genkeypair and the -ext eku=codeSigning option.
  3. Sign with jarsigner -keystore sign.jks app.jar devsign.
  4. Run jarsigner -verify app.jar to confirm the result.
keytool and jarsigner signing a JAR in terminal

jarsigner signs the test JAR with a self-signed code signing key.

For more keystore commands, see our list of the common Java keytool commands.

How Do You Verify a Signed JAR?

Run jarsigner -verify -verbose -certs app.jar. A good signature prints jar verified. The output then lists warnings about the certificate chain, a self-signed signer and a missing timestamp. Those warnings are normal for a test key, and they tell you what a public certificate would fix.

jarsigner verify output with self signed warnings

Verification passes, with warnings (output shortened to the key lines).

The same warnings appear for any signer that Java cannot trace to a trusted root. A certificate from a public CA removes the chain warning, as our guide to the code signing certificate explains.

What Happens If Someone Changes a Signed JAR?

Java rejects the file. We swapped one class file inside our signed JAR, then ran the verify command again. The jarsigner tool stopped with a SHA-256 digest error. Running the JAR with java -jar failed too, with the same security exception.

jarsigner SHA 256 digest error on a modified class

A changed class file fails verification with a digest error.

This is the integrity half of signing. The identity half depends on a certificate that Java and your users trust.

Why Should You Add a Timestamp When Signing?

A timestamp proves the JAR was signed while the certificate was still valid. Without one, signature checks can fail after the certificate expires. Add -tsa with your CA's timestamp URL when you sign. Our sandbox has no outside network, so our timestamp attempt failed with an UnknownHostException.

So we did not run a real timestamp, but the verify warning shows what is at stake. Our page on code signing timestamping has the details.

Can You Use an SSL Certificate for Code Signing?

No. A TLS certificate is issued for server authentication, and a code signing certificate carries a different extended key usage. We made a key with only the serverAuth usage and signed a JAR. The jarsigner tool then warned that the key usage does not allow code signing.

jarsigner code signing extended key usage warning

A serverAuth-only key triggers a code signing warning.

What Is the Difference Between Self-signed and CA-issued Certificates?

A self-signed certificate costs nothing but nobody else trusts it. A CA-issued certificate comes after identity checks and chains to a trusted root. Extended validation adds stricter vetting. The table compares the three on the points that matter for Java.

TypeWho trusts itBest forNotes
Self-signedOnly machines where you install itTesting and internal toolsFree, and Java warns about the chain
OV code signingSystems that trust the issuing CAPublic JARs and installersThe CA checks your organisation
EV code signingSystems that trust the issuing CAHigher-assurance releasesStricter vetting by the CA

Prices vary by CA, so we give no figures here. Our code signing provider comparison lists current options.

Which Keystore Format Should You Use?

Use PKCS12 unless a tool demands otherwise. On our JDK 21 test machine, keytool reported the type PKCS12, even though we named the file sign.jks. The extension does not decide the format. Check the real type with keytool -list, and convert only when a build tool asks. Then keep one keystore per signing identity.

What Errors Do You Hit When Signing a JAR?

Three errors come up most. A wrong alias, a wrong keystore password and an already signed JAR each give a different message. We triggered the first two on purpose, so the wording below is real. Fix the alias or password, then run the command again.

  • Wrong alias: jarsigner says the certificate chain was not found for that alias.
  • Wrong password: jarsigner reports that the keystore password was incorrect.
  • Unsigned check: jarsigner -verify prints jar is unsigned when no signature files exist.

What Does Signing Give You?

Signing gives users two checks. They can see who published the JAR, and they can detect any change made after release. Signing does not prove the code is safe, because even trusted signers can ship bugs or malicious code by mistake.

  • Publisher identity from the certificate subject.
  • Tamper detection through the hashes in the manifest.
  • Longer-lived signatures when you add a timestamp.

How Long Does a Code Signing Certificate Last?

New publicly trusted code signing certificates last at most 460 days. The CA/Browser Forum's ballot CSC-31 cut the limit from 39 months, effective 1 March 2026. Certificates issued earlier stay valid until their own end date. Plan a yearly renewal in your release process.

Renewing means a new key or certificate, so update your build pipeline too. Our guide on how to renew a code signing certificate walks through it.

How Do You Get a Java Code Signing Certificate?

Generate a key pair and a certificate signing request, send it to a CA, and pass its validation. The CA then issues the certificate. You import it into your keystore under the same alias. We ran the CSR step but could not run the CA steps here.

  1. Create the key pair with keytool -genkeypair.
  2. Generate the request with keytool -certreq -alias devsign -file devsign.csr.
  3. Submit the CSR to the CA and complete its identity checks.
  4. Import the signed certificate and chain with keytool -importcert.

Keep the private key safe, because anyone who holds it can sign code in your name. Some CAs require the key on a hardware token or HSM.

Do Java Applets Still Need Signing?

Not anymore. Browsers no longer support applets, and OpenJDK completed JEP 504 to remove the Applet API in JDK 26. Signing still matters for JAR files that ship libraries, desktop apps and installers. Older guides that focus on applets are out of date.

Frequently Asked Questions

What is a Java code signing certificate?

It is a certificate whose private key signs JAR files. It shows who published the code and whether the code changed after signing.

How do I sign a JAR file?

Create or import a key in a keystore, then run jarsigner with the keystore, the JAR and the key alias. Add -tsa to include a timestamp.

Can I sign Java code without a certificate?

You can use a self-signed certificate for testing. Public users will not trust it, and Java prints chain warnings.

How much does a Java code signing certificate cost?

The price depends on the CA and on the validation level. Compare current offers before you buy.

How long is a code signing certificate valid?

New public certificates last at most 460 days since 1 March 2026. Older ones keep their original end date.

Can I use an SSL certificate for code signing?

No. A TLS certificate lacks the code signing key usage, and jarsigner warns about it.

What happens when a code signing certificate expires?

New signing stops working. Signatures with a valid timestamp can still verify afterward.

Is a Java code signing certificate the same as a JCE certificate?

No. A JCE code signing certificate is a separate kind for security providers. Check the vendor's own documentation before you apply.