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 pairs Dual DKIM (RFC 6376) and DMARC alignment with active Port 25 bounce checks and per-key agent spend guards.