Course contentsShow
← Security
Lesson 123 of 3,0523. Symmetric Cryptography Deep DiveFree lesson

Encrypt-then-MAC Construction

The secure authenticated encryption approach: encrypt plaintext first, then compute MAC over ciphertext.

Encrypt-then-MAC Construction

What you'll learn: How to securely combine encryption and authentication by computing the MAC over the ciphertext.


The Secure Path to Authenticated Encryption

You've learned that encryption alone doesn't guarantee integrity, and that authentication matters. But how you combine encryption and MAC operations is critical—get it wrong, and attackers can exploit the weakness.

Encrypt-then-MAC is the safest construction: you first encrypt your plaintext, then compute the MAC over the resulting ciphertext (and any associated data like IVs). This means the MAC protects the encrypted data itself.

Why This Order Matters

Think of it like sealing a letter in an envelope, then putting a tamper-evident seal on the outside. The recipient checks the seal first—if it's broken, they don't even open the envelope. This prevents attacks that exploit how the system reacts to tampered ciphertexts.

The process looks like this:

  1. Encrypt: ciphertext = Encrypt(key1, plaintext)
  2. Compute MAC: tag = MAC(key2, ciphertext)
  3. Send both: ciphertext + tag

On receipt, you verify the MAC before decrypting. If the MAC fails, you reject the message immediately without touching the decryption function. This shields your decryption logic from tampered inputs—critical for preventing attacks like padding oracles.

Alternatives Are Riskier

Other combinations exist (MAC-then-Encrypt, Encrypt-and-MAC), but both have been exploited in real systems. Encrypt-then-MAC is the construction cryptographers recommend and is used in protocols like IPsec and TLS 1.3.

Key Takeaway: Encrypt-then-MAC is the gold standard for authenticated encryption—encrypt first, then MAC the ciphertext, and always verify the MAC before decrypting.