CKTIS / Java
AEADBadTagException — ciphertext authentication failure
AEADBadTagException means that a Cipher operating in an AEAD mode, such as GCM or CCM, could not verify the authentication tag. Reject the data rather than treating it as successfully decrypted.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
import javax.crypto.AEADBadTagException;
// public class AEADBadTagException extends BadPaddingException
new AEADBadTagException();
new AEADBadTagException("Authentication failed");javax.crypto.AEADBadTagException is a checked exception available since Java 7, in the javax.crypto package of the java.base module. It extends BadPaddingException, but here it signals failed AEAD tag verification rather than an ordinary padding problem. The AEADBadTagException() constructor supplies no detail message; AEADBadTagException(String msg) accepts one.
AEAD authenticates encrypted data and optional additional authenticated data (AAD), which is not encrypted. During decryption, Cipher.doFinal(...) throws this exception if the tag does not match. The exception alone does not distinguish tampering from corruption or mismatched inputs such as the key, IV, or AAD.
After failure, reject the data; do not use any partial plaintext. If handling AEADBadTagException and BadPaddingException separately, put the more specific catch block first. Do not base program logic on the exception message text.
The example flips one tag bit and expects Authentication failed. Its fixed key and IV are only for an isolated demonstration: in real GCM encryption, never repeat an IV with the same key. The documentation scope is Java SE 21; the repository's production runtime has not been attested.
Examples
import java.nio.charset.StandardCharsets;
import javax.crypto.AEADBadTagException;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class Main {
public static void main(String[] args) throws Exception {
// Fixed key and IV are for this isolated demonstration only.
var key = new SecretKeySpec(new byte[16], "AES");
var params = new GCMParameterSpec(128, new byte[12]);
var encryptor = Cipher.getInstance("AES/GCM/NoPadding");
encryptor.init(Cipher.ENCRYPT_MODE, key, params);
byte[] sealed = encryptor.doFinal(
"hello".getBytes(StandardCharsets.UTF_8));
// Flip one bit in the appended authentication tag.
sealed[sealed.length - 1] ^= 1;
var decryptor = Cipher.getInstance("AES/GCM/NoPadding");
decryptor.init(Cipher.DECRYPT_MODE, key, params);
try {
decryptor.doFinal(sealed);
throw new AssertionError("Expected authentication failure");
} catch (AEADBadTagException expected) {
System.out.println("Authentication failed");
}
}
}Result
Authentication failed
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.