Skip to main content

Try it Live

Run AES-GCM examples in the interactive playground

Overview

AES-GCM decryption reverses the encryption process while verifying the authentication tag. This ensures that:
  1. Ciphertext hasn’t been tampered with (integrity)
  2. Correct key and nonce were used (authentication)
  3. AAD matches encryption (if used)
Decryption fails completely if authentication fails - no partial plaintext is returned.

Decryption Operation

Basic Decryption

How It Works

AES-GCM decryption involves three main steps:
  1. Separate Components
    • Extract authentication tag (last 16 bytes)
    • Extract ciphertext (remaining bytes)
  2. Verify Authentication Tag
    • Recompute tag using ciphertext, AAD, nonce, and key
    • Compare computed tag with provided tag (constant-time)
    • Fail immediately if tags don’t match
  3. Decrypt Ciphertext (only if authentication passes)
    • Generate keystream using counter mode
    • XOR keystream with ciphertext to produce plaintext
    • Return plaintext
Critical: Authentication is verified BEFORE decryption to prevent timing attacks and ensure tampered data is never returned.

Parameters

Ciphertext (Required)

The encrypted data including the 16-byte authentication tag:
Format:
Error if too short:

Key (Required)

Must be the same key used for encryption:

Nonce (Required)

Must be the same nonce used for encryption:
CRITICAL: Nonce must be exactly 12 bytes (96 bits)

Additional Authenticated Data (Optional)

If AAD was used during encryption, the exact same AAD must be provided for decryption:
AAD is part of authentication - any change (including omission) causes decryption to fail.

Error Handling

Authentication Failures

Decryption throws DecryptionError if authentication fails:

Common Failure Scenarios

1. Wrong key:
2. Wrong nonce:
3. Tampered ciphertext:
4. Tampered authentication tag:
5. Wrong AAD:

Error Messages

Security Properties

Constant-Time Verification

Tag verification is performed in constant time to prevent timing attacks:

All-or-Nothing Decryption

If authentication fails, no plaintext is returned - not even partial data:
This prevents padding oracle attacks and ensures data integrity.

Advanced Usage

Batch Decryption

Decrypt multiple messages in parallel:

Extract and Decrypt

Parse stored format and decrypt:

Verify Without Decrypting

Check if decryption would succeed without actually decrypting:
Note: This still performs decryption internally. GCM doesn’t support tag verification without decryption.

Performance

Decryption Speed

Similar to encryption (hardware-accelerated):
  • With AES-NI: ~2-5 GB/s
  • Software-only: ~50-200 MB/s

Benchmarks

Examples

Wallet Decryption

Database Field Decryption

Authenticated Message Decryption

Common Mistakes

Not Handling Errors

Using Wrong Parameters

Partial Decryption Assumptions

References