Why ECB Mode Leaks Penguins and Why AEAD (AES-GCM) Matters for API Payloads A developer explains why AES in ECB mode leaks plaintext structure—identical 16-byte blocks produce identical ciphertext, preserving patterns in JSON and images—and why modern APIs should use AEAD ciphers like AES-256-GCM or ChaCha20-Poly1305, which add integrity verification and prevent padding-oracle attacks. The writeup includes a TypeScript Web Crypto example that binds a tenantId to an encrypted payload via additionalData, so a ciphertext moved between tenants fails authentication on decrypt. 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.