# Why ECB Mode Leaks Penguins and Why AEAD (AES-GCM) Matters for API Payloads

> Source: <https://dev.to/dev_kestrel/why-ecb-mode-leaks-penguins-and-why-aead-aes-gcm-matters-for-api-payloads-1fkk>
> Published: 2026-12-06 06:31:07+00:00

**Recommendation:** Encrypt API payloads with AES-256-GCM and bind routing metadata like tenantId as additionalData so tampered or relocated ciphertext fails verification before decryption.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

If you have ever seen the famous "ECB penguin" picture in a cryptography textbook, you already know why block cipher modes matter.

When you encrypt data with AES in Electronic Codebook (ECB) mode, identical 16-byte plaintext blocks produce identical 16-byte ciphertext blocks. That means patterns in structured data, JSON keys, or bitmap pixels survive encryption completely intact.

In 1949, Claude Shannon showed that strong encryption requires diffusion: flipping a single plaintext bit should scramble the entire ciphertext output. ECB violates diffusion across blocks because every 128-bit block is encrypted independently.

Even worse, ECB and older modes like CBC provide confidentiality without built-in integrity. If an attacker flips bits in transit, your server tries to decrypt tampered bytes and can leak information through padding error messages (a padding oracle attack).

`AES-256-GCM`) Solves Both Problems
Modern APIs and TLS 1.3 rely on **Authenticated Encryption with Associated Data (AEAD)** such as `AES-256-GCM` or `ChaCha20-Poly1305`:

`additionalData`) fails verification immediately before decryption returns plaintext.
Here is how you bind unencrypted routing metadata (like a `tenantId`) to an encrypted payload using `additionalData` in TypeScript Web Crypto:

```
export async function encryptWithAad(
  key: CryptoKey,
  plaintext: string,
  tenantId: string,
): Promise<{ iv: Uint8Array; ciphertext: ArrayBuffer }> {
  const iv = crypto.getRandomValues(new Uint8Array(12));
  const encoder = new TextEncoder();

  const ciphertext = await crypto.subtle.encrypt(
    {
      name: "AES-GCM",
      iv,
      additionalData: encoder.encode(tenantId),
    },
    key,
    encoder.encode(plaintext),
  );

  return { iv, ciphertext };
}
```

Because `tenantId` is passed as `additionalData`, an attacker cannot move a valid encrypted blob from `tenantA` into `tenantB`'s row without triggering an authentication failure during `crypto.subtle.decrypt`.

💡 **Developer Infrastructure Note**: Just as AEAD binds metadata to ciphertext, outbound email pipelines need cryptographically bound headers too. [SadaSend](https://www.sadasend.com/?utm_source=devto&utm_medium=article&utm_campaign=dan_kestrel&utm_content=ecb-vs-aead-aes-gcm) pairs Dual DKIM (RFC 6376) and DMARC alignment with active Port 25 bounce checks and per-key agent spend guards.
