Skip to content
Tech Interview Prep
Technical interview guide

Encryption Fundamentals

Symmetric vs. asymmetric encryption, hashing, and how TLS combines them.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: FIPS 197 update 1, NIST SP 800-57 Part 1 Rev. 5, RFC 8446, and official OWASP guidance accessed 2026-08-31..

Overview

Curated: · Written: · Reviewed:

Encryption Fundamentals

In one line

Encryption gives confidentiality, MACs and AEAD tags give integrity, signatures give public verifiability, and hashes give one-way digests. Production systems use asymmetric crypto only to agree on or wrap keys, and symmetric AEAD to protect the data. State the property and the adversary before you name a primitive, because the adversary decides which primitive is enough.

Key definitions

  • Confidentiality: only key holders can read the data. Delivered by AES, ChaCha20, RSA-OAEP and key agreement.
  • Integrity: tampering is detectable. Delivered by HMAC, AEAD tags and signatures.
  • AEAD: one construction that encrypts and tags together. Associated data (AAD) such as tenant ID is authenticated but not encrypted.
  • Nonce: must never repeat under one key. Reuse exposes the XOR of two plaintexts and, for GCM, the authentication key.
  • KDF: derives purpose-separated keys from high-entropy input (HKDF). It does not make a password strong.
  • Envelope encryption: a data key encrypts the data, and a key-encryption key wraps the data key, so rotating the outer key does not re-encrypt the data.

Formulas and complexity

c1⊕c2=m1⊕m2(same key and nonce)c_1 \oplus c_2 = m_1 \oplus m_2 \quad \text{(same key and nonce)}

For $n$ random 96-bit nonces under one key, the collision probability is about

p≈n2297p \approx \frac{n^2}{2^{97}}

At $n = 2^{32}$ messages this is about $2^{-33}$, so rotate the data key well before that point. Quote AES-GCM throughput as multiple GB/s with AES-NI, and RSA-2048 public-key operations as thousands of times slower per operation than AES.

How it works

In TLS 1.3 the client and server each send an ephemeral key share. The ECDHE secret is fed through HKDF to derive per-direction traffic keys. The server signs the handshake transcript with its certificate key, which authenticates the server to the client. Records are then protected by AES-GCM or ChaCha20-Poly1305 with per-record nonces. The ephemeral keys give forward secrecy, and the client is authenticated only when mTLS is used.

Client: ephemeral X25519 key share Server: key share plus certificate signature over transcript ECDHE shared secret HKDF derives traffic keys per direction AEAD records with per-record nonces Server authenticated by certificate, client only with mTLS

When to use and when not to

NeedUseAvoid
Bulk data confidentialityAES-256-GCM or ChaCha20-Poly1305ECB, or CBC without a MAC
Share a key with parties you have never metKey agreement, or RSA-OAEP to wrap a symmetric keyRSA over the whole payload
Integrity between holders of one secretHMACPublic verification, since any verifier can forge
Public verification or release artifactsSignatures such as Ed25519 or ES256HMAC for anything third parties must check
Password storageArgon2id, or bcrypt or scrypt where already deployedSHA-256 or any fast hash
Indexed lookup by a secret valueKeyed digest such as HMAC-SHA-256 under a server-held keyRandomized ciphertext, which never matches twice

Traps interviewers probe

  1. Encrypting a lookup key with a random nonce. Each encryption produces different output, so the indexed lookup always misses. Fix: index a deterministic keyed digest of the presented key, and store the encrypted copy in a separate column if you need it.
  2. Repeating a GCM nonce. Fix: use random 96-bit nonces only within a counted message budget, or a counter that is guaranteed to be monotonic, and rotate the data key before the budget is spent.
  3. ECB, or CBC without a MAC. Fix: a high-level AEAD API with AAD that binds tenant and row ID, so a ciphertext cannot move to another record.
  4. Fast hashing for passwords, or running HKDF on a password. Fix: Argon2id with a unique salt per password. Use HKDF only on high-entropy keys.
  5. One key for several purposes. Fix: HKDF-Expand with a distinct info string per purpose, so the encryption key and the MAC key are never the same bytes.

Interview tips

Opening: name the property and the adversary first, then the primitive, then the key management. Interviewers score the reasoning, not the algorithm name.

Expected follow-ups:

  • Why not RSA for everything? Throughput, ciphertext expansion, and the padding-oracle history of PKCS#1 v1.5.
  • What happens if a nonce repeats? The XOR of the plaintexts leaks, and in GCM the authentication key can be recovered, so tags can be forged afterwards.
  • HMAC or signature for JWTs? The deciding factor is who must verify. HS256 means every verifier holds the signing secret.
  • Is TLS on enough? Only up to the termination point. Verify that certificate validation is on, and that internal hops are encrypted too.
  • A key is compromised. Contain it, analyze exposure, replace the trust roots, and re-encrypt where the exposure requires it. Generating a new key is not enough.

30-second outline: The adversary is someone who can read the storage tier, not the network. I need confidentiality and integrity, so I use AES-256-GCM with a per-record nonce and tenant ID as AAD. The data key is wrapped by a KMS-held key, which gives envelope encryption. Every ciphertext records the key version, so rotation can run online. Asymmetric crypto appears only for key agreement or key wrapping. Authorization is a separate control and is still required.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.