About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
When keytool or a Java server such as Tomcat fails with java.io.IOException: Keystore was tampered with, or password was incorrect, Java loaded a JKS keystore file and its integrity check failed. Either the store password given is not the one the file was protected with, or the file has changed since that password was set. The message cannot tell the two apart, so test the password with keytool, outside the server, before changing anything.
What the message means
In the OpenJDK source at tag jdk-21+35, JavaKeyStore.engineLoad reads the whole keystore and, "If a password has been provided", checks a keyed digest at the end. When the check fails it throws IOException("Keystore was tampered with, or password was incorrect") wrapping UnrecoverableKeyException("Password verification failed"). The digest covers the file contents, so a wrong password and a changed file both fail the same way. The keytool page describes -storepass as "The password that is used to protect the integrity of the keystore."
Three nearby messages differ:
- A PKCS12 keystore with the wrong password raises other texts, from
PKCS12KeyStore:Integrity check failed:followed byjava.security.UnrecoverableKeyException: Failed PKCS12 integrity checkingwhen its integrity check fails, andkeystore password was incorrect(lower-case k), with the causefailed to decrypt safe contents entry, when decrypting its contents fails. - A wrong key password, not the store password, raises
Cannot recover keyfromKeyProtector. The keytool page says-keypassprotects the private key separately from the store. - In the JDK,
SunEntriesregisters theJKSkeystore type assun.security.provider.JavaKeyStore$DualFormatJKS. Per its source comment it "supports JKS and PKCS12 file formats" and probes the first bytes to choose. Our own reading: a PKCS12 file loaded as type JKS is read by the PKCS12 code and gives one of the PKCS12 texts above, not this one.
In Tomcat 10.1.62's connector reference, certificateKeystorePassword is "The password to use to access the keystore containing the server's private key and certificate." The page adds: "If not specified, a default of changeit will be used." For certificateKeystorePasswordFile, it says the attribute "takes precedence over certificateKeystorePassword". certificateKeyPassword is for the private key and, for JSSE, defaults to the keystore password. certificateKeystoreFile defaults to .keystore in the home of the user running Tomcat. If no type is set and the system property javax.net.ssl.keyStoreType is not set either, Tomcat's page says a default of "JKS" is used.
Likely causes
Our own reading of the common causes.
| Cause | What you see | How to confirm |
|---|---|---|
The store password in server.xml is not the file's password |
Error at every start since a certificate or keystore change | keytool -list with the password in server.xml fails the same way |
The attribute is missing, so Tomcat tries changeit |
No certificateKeystorePassword in the Certificate element |
The attribute is absent from server.xml |
A certificateKeystorePasswordFile overrides the attribute |
The attribute looks right but the error stays | server.xml names a password file; its content is the password used |
| The file changed after the password was set | The right password still fails | The same password works on the original copy of the file |
| The path points at a different keystore | Another file's password is needed | keytool -list shows aliases that are not yours |
Prove the cause before changing anything
All of these read only.
1. Read the whole stack trace. Note whether the cause line says Password verification failed (the JKS text above) or the PKCS12 text, and which file Tomcat or the application tried to load.
2. Read what Tomcat is configured to use. Search server.xml for the keystore attributes; relative paths are resolved against $CATALINA_BASE:
grep -n -E "certificateKeystore|certificateKey" /opt/tomcat/conf/server.xml
Note the file, the type, whether a password file is set, and whether a key password is set.
3. Test the store password outside Tomcat. Run keytool with no -storepass, so that it prompts and the password stays out of the shell history and the process list. The keytool page says the password is prompted for when the option is not given.
keytool -list -keystore /opt/tomcat/conf/tls/app.jks
A good result lists the entries; by default keytool prints a SHA-256 fingerprint for each certificate. A bad result is the same IOException.
4. Check that the file itself reads. The keytool page says that when "retrieving information from the keystore, the password is optional" and that without one, "the integrity of the retrieved information can't be verified and a warning is displayed". Our own reading: pressing Enter at the prompt separates a readable file from a failed integrity check, because a listing that works with only a warning shows the file structure is intact.
5. Compare the file with its source. If the file travelled by copy, download or a deployment tool, compare its size and checksum with the original. Our own reading: any difference breaks the digest, and a text-mode transfer is a common way to cause one.
Fix
The password in server.xml is wrong
First save the current state:
cp -p /opt/tomcat/conf/server.xml /opt/tomcat/conf/server.xml.2026-12-03
Risk: the next edit changes the keystore password in Tomcat's configuration, and Tomcat has to be restarted for it to take effect. Every request in flight is dropped and the HTTPS connector is down until the restart succeeds. A wrong password leaves it failing as before, and server.xml holds the password in clear text, so only trusted accounts may read the file.
Edit the Certificate element in server.xml: set certificateKeystorePassword to the password that step 3 accepted. If server.xml also names a certificateKeystorePasswordFile, that attribute "takes precedence over certificateKeystorePassword", so this edit does not take effect until the password file holds the same password; changing that file is a separate change with its own save and back-out, and this step does not cover it. Then stop Tomcat with its script:
/opt/tomcat/bin/shutdown.sh
Our own advice: wait until the old Tomcat process has gone, because the script only sends the stop command. Then start Tomcat:
/opt/tomcat/bin/startup.sh
Only if you need to back out, restore the saved file and restart.
Disruptive step: the next command puts back the saved server.xml, which discards the new password. Tomcat then has to be stopped and started again, which drops every request in flight and takes the HTTPS connector down until the start succeeds.
cp -p /opt/tomcat/conf/server.xml.2026-12-03 /opt/tomcat/conf/server.xml
After it, stop Tomcat with /opt/tomcat/bin/shutdown.sh, wait until the old process has gone, and start it with /opt/tomcat/bin/startup.sh. Then check that the file is back as saved. This reads only:
grep -n -E "certificateKeystore|certificateKey" /opt/tomcat/conf/server.xml
The file changed or is damaged
If step 3 fails with the password you know is right, and the original copy of the keystore works with it, the remedy is the original file in place of the damaged one. The steps follow.
First save the current state:
cp -p /opt/tomcat/conf/tls/app.jks /opt/tomcat/conf/tls/app.jks.2026-12-03
Risk: the next command overwrites the keystore file that Tomcat reads with a different file, and Tomcat has to be restarted to load it. If the original is older than the current certificate, the site serves an expired or wrong certificate after the restart, and requests in flight are dropped.
Copy the original over the file:
cp -p /home/admin/keystore-original/app.jks /opt/tomcat/conf/tls/app.jks
Then stop Tomcat with /opt/tomcat/bin/shutdown.sh, wait until the old process has gone, and start it with /opt/tomcat/bin/startup.sh.
Only if you need to back out, restore the saved copy and restart.
Disruptive step: the next command puts back the saved keystore file, which discards the original you copied in. Tomcat then has to be stopped and started again, which drops every request in flight and takes the HTTPS connector down until the start succeeds.
cp -p /opt/tomcat/conf/tls/app.jks.2026-12-03 /opt/tomcat/conf/tls/app.jks
After it, stop Tomcat with /opt/tomcat/bin/shutdown.sh, wait until the old process has gone, and start it with /opt/tomcat/bin/startup.sh. Then check that the file lists as before. This reads only, and prompts for the password:
keytool -list -keystore /opt/tomcat/conf/tls/app.jks
The password is lost
The keytool page documents -storepasswd for changing a password that is already known: it needs the current one. Our own reading: keytool cannot recover a lost store password, so with the password gone the remaining route is a new keystore built from the original private key and certificate files, using the -importkeystore command described on the same page, and that is a change of its own.
Example (illustrative): On app01, a colleague replaced /opt/tomcat/conf/tls/app.jks on 3 December with a keystore for the renewed certificate and gave it a new store password. server.xml still carries the old one, and Tomcat's HTTPS connector fails at start with Keystore was tampered with, or password was incorrect. keytool -list with the old password fails the same way; with the new password it lists one entry, the alias tomcat. The administrator saves server.xml, sets certificateKeystorePassword to the new value and restarts Tomcat.
Confirm the fix
keytool -list -keystorewith the password now inserver.xmllists the entry.- Tomcat starts without the
IOExceptionand the HTTPS connector listens. - A client sees the expected certificate.
keytool -printcert -sslserver app.example.com:443prints the certificate the server presents.
What to watch afterwards
- A certificate renewal that creates a new keystore also sets its password;
server.xmlhas to follow it. - Deployment tools that process files as text can alter a binary keystore.
- Keep the keystore, its password and its source copy together under access control.
Read next
Related articles you may want next.
- TroubleshootingJava "PKIX path building failed: unable to find valid certification path to requested target": see what the server sends, then fix the trust store or the chainPKIX path building failed: unable to find valid certification path. Check the server's chain with keytool, find the trust store in use, then import the CA.Read article
- Troubleshootingnginx will not start after a certificate change: key values mismatch between certificate and private keynginx SSL_CTX_use_PrivateKey_file failed, key values mismatch: prove which file is wrong with openssl, fix the pair or chain order, and test with nginx -t.Read article
- TroubleshootingTomcat java.net.BindException: Address already in use - find what holds the port, then stop it or move the connectorTomcat says java.net.BindException: Address already in use? Find what holds port 8080 or the shutdown port with ss or netstat, then stop it or move it.Read article
Risks and limits
- These commands have not been run or lab-tested.
- The message text is read from JDK 21 source (
jdk-21+35); other releases may word it differently. - Our own reading of the digest check is that any change to the file fails it.
- Passwords on a command line can be seen by other users; prefer the prompt.
Sources
- The keytool Command — Oracle, JDK 21 Specifications, no date shown, accessed 3 December 2026
- Apache Tomcat 10 — Apache Software Foundation, SSL/TLS Configuration How-To, version 10.1.62, 10 November 2026, accessed 3 December 2026
- Apache Tomcat 10 Configuration Reference — Apache Software Foundation, The HTTP Connector, version 10.1.62, 10 November 2026, accessed 3 December 2026
- JavaKeyStore.java — OpenJDK source, tag jdk-21+35, no date shown, accessed 3 December 2026
- PKCS12KeyStore.java — OpenJDK source, tag jdk-21+35, no date shown, accessed 3 December 2026
- SunEntries.java — OpenJDK source, tag jdk-21+35, no date shown, accessed 3 December 2026
- KeyProtector.java — OpenJDK source, tag jdk-21+35, no date shown, accessed 3 December 2026
This article was originally published on .