Quiz
Six crypto questions you may have to answer in a design review. Pick the right primitive and explain why.
Six crypto design questions
EXAMPLE
# ============================================================
# Q1) Storing user passwords
# ============================================================
# ANSWER: Argon2id (preferred) with memory_cost=64*1024, time_cost=3,
# parallelism=4. Bcrypt cost >= 12 is the fallback when Argon2 is unavailable.
# NEVER SHA-256 / SHA-3 / MD5 — too fast against GPUs.
# ============================================================
# Q2) Encrypting a session cookie at the app server
# ============================================================
# ANSWER: AES-256-GCM with a per-message random 96-bit nonce. The nonce + ciphertext
# go in the cookie; the key lives in the app env (rotate per deploy if possible).
# NEVER reuse the same (key, nonce) pair — catastrophic.
# ============================================================
# Q3) Signing webhook payloads from your server to a customer
# ============================================================
# ANSWER: HMAC-SHA256 over the body + timestamp. Send the signature and a
# timestamp in headers. On receipt, constant-time compare AND reject if the
# timestamp is more than 5 minutes old (replay protection).
# ============================================================
# Q4) JWT for an internal service to call another internal service
# ============================================================
# ANSWER: RS256 or EdDSA (Ed25519) signed JWT. Hard-code the expected
# algorithm at verification. Pin issuer + audience. Short expiry (5-15 min)
# with the next-hop responsible for getting a fresh one.
# NEVER 'alg: none', NEVER accept the alg from the header without checking.
# ============================================================
# Q5) Generating an unguessable URL token (password reset, magic link)
# ============================================================
# ANSWER: 32 bytes from a CSPRNG, base64url-encoded.
# Python: secrets.token_urlsafe(32)
# Node: crypto.randomBytes(32).toString('base64url')
# Store ONLY the SHA-256 of the token in the DB; compare with constant-time.
# Expire in 15-30 minutes.
# ============================================================
# Q6) Sharing a secret with a partner over an insecure channel
# ============================================================
# ANSWER: do NOT email it. Use:
# - Onetimesecret.com (or self-hosted onetimesecret)
# - Encrypted Slack DM via a shared secrets vault
# - Vault / Doppler / 1Password Secrets Automation
# - 'gpg --symmetric' encrypted blob over any channel + passphrase via a SECOND channel
# Rotate immediately after first use.
# ============================================================
# Bonus — when is HMAC-SHA1 acceptable?
# ============================================================
# ANSWER: legacy AWS Signature V2 (deprecated), some HOTP/TOTP variants
# (HMAC-SHA1 is still safe inside HMAC construction even though plain SHA-1
# is broken). For new code, prefer HMAC-SHA256.
# ============================================================
# Scoring
# ============================================================
# 6 / 6 -> ready to lead crypto design reviews
# 4 / 6 -> revisit crypto/cheatsheet + libraries lesson
# < 4 -> read 'Cryptography Engineering' (Schneier/Ferguson)
Why it matters
Pick the highest-level primitive available (AEAD over raw cipher, password hasher over hash function, HKDF over manual key derivation). The high-level APIs hide the misuse-prone knobs — nonce reuse, padding oracles, key-derivation shortcuts — that have shipped half of the cryptographic CVEs of the last decade.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…