Convert a PEM Certificate to a Java Keystore
Java does not read PEM files the way Nginx and Apache do. It reads a keystore: one file that holds the private key, the certificate and the chain, addressed by an alias. Tomcat supports JKS, PKCS11 and PKCS12 keystores (Tomcat SSL how-to), and PKCS12 is the one to prefer unless a tool forces JKS. Converting from PEM is two commands, and the errors that follow are almost always about the alias or the chain.
What each format is for
| Format | Extension | Used by |
|---|---|---|
| PEM | .pem, .crt, .key | Nginx, Apache, HAProxy, most Linux services |
| PKCS12 | .p12, .pfx | Java since 9, IIS, Windows, macOS Keychain |
| JKS | .jks | Older Java tooling, some enterprise middleware |
PKCS12 is the better default today. JKS is a Java-only format that has been deprecated as a default since Java 9, and it cannot hold the same metadata. Convert to JKS only when a tool asks for it by name.
Convert PEM to a Java keystore, step 1: PKCS12
You need the private key and a certificate file that includes the chain. If your provider gave you separate files, concatenate the leaf certificate and the intermediate, leaf first.
cat certificate.crt ca_bundle.crt > fullchain.pem
openssl pkcs12 -export \
-in fullchain.pem \
-inkey private.key \
-out keystore.p12 \
-name myserver \
-passout pass:ChangeMe123
The -name flag sets the alias. Java refers to the entry by this name, and some frameworks ask for it explicitly, so choose something you will type correctly later: tomcat, springboot, myserver.
The order matters. If you concatenate the intermediate before the leaf, the keystore builds without complaint and some clients then fail to build a path to a trusted root. Check the order before you convert.
Convert PEM to a Java keystore, step 2: PKCS12 to JKS
keytool -importkeystore \
-srckeystore keystore.p12 -srcstoretype PKCS12 \
-srcstorepass ChangeMe123 \
-destkeystore keystore.jks -deststoretype JKS \
-deststorepass ChangeMe123 \
-destkeypass ChangeMe123
Without -destkeypass, some keytool versions warn that the key password differs from the store password. Many servers tolerate that; a few refuse to start. Setting both to the same value removes the question.
Step 3: verify before you deploy
keytool -list -v -keystore keystore.p12 -storetype PKCS12
What you want to see: exactly one entry with your alias, an entry type of PrivateKeyEntry, a chain of two or three certificates, and a validity window that matches the certificate you bought or issued.
- TrustedCertEntry instead of PrivateKeyEntry. The key was not included. Rebuild with
-inkey. - Chain length of one. The intermediate is missing. Rebuild from fullchain.pem.
- Two entries. You converted a keystore that already had a certificate in it. Start from a clean file.
If the private key has a passphrase, OpenSSL will prompt for it during the export. That is fine for the export, but the resulting keystore must have a password the server knows, and a key protected by a second passphrase will break some servers at startup.
Doing it without a terminal
The SSL converter builds a PKCS12 or PFX from a PEM certificate and key in the browser, which covers the common case of a certificate downloaded as three text files. Before converting, run the pair through the key matcher: converting a mismatched pair produces a keystore that fails at the worst possible moment, and the mismatch is invisible until then.
If you are not sure which OpenSSL flags your situation needs, the OpenSSL command builder assembles the command from a form, including the pkcs12 export and the verification steps.
Where this shows up in practice
The three places this conversion is asked for most: Tomcat, which reads a keystore in its Connector; Spring Boot, which takes a PKCS12 through a few properties; and any Java service that terminates TLS itself, such as an embedded Jetty or a Kafka broker. In all three, the same two mistakes dominate: wrong alias, incomplete chain.
After the conversion
Once the service is running, confirm what it actually serves with the SSL checker rather than trusting the keystore listing. A complete chain in the keystore and an incomplete chain on the wire are different failures, and only the second one is visible to visitors.
Related reading: installing a certificate on Tomcat, HTTPS in Spring Boot and generating a private key and CSR.
Frequently Asked Questions
Which keystore format should I use, JKS or PKCS12?
PKCS12. It is an internet standard, OpenSSL and keytool both read it, and newer Java versions default to it. JKS only when an old tool cannot take anything else.
Why does my server say the key and certificate do not match?
The keystore holds a key from one certificate request and a certificate from another. Rebuild the keystore from the key and chain that were issued together, and confirm with a keytool listing that shows one entry.
Does converting the certificate change it?
No. The certificate and key are the same bytes, wrapped in a container with a password. Nothing about the certificate, its names or its expiry changes.
✅ Post-Installation Verification & SEO Checklist
After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:
- Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
- Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
- Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
- Confirm both root and
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.