Applied Cryptography and Key Management Questions
Selecting and applying cryptographic primitives correctly: symmetric and asymmetric encryption, hashing, digital signatures, key derivation, secure random number generation, and public key infrastructure. Covers key lifecycle management, key exchange and distribution, choosing appropriate algorithms for a given constraint set including resource-constrained environments, and the forward-looking side of algorithm lifecycle: cryptographic agility and algorithm-migration strategy, forward secrecy, and the post-quantum cryptography transition and planning upgrades without breaking existing data or interoperability. The applied-crypto engineering layer, distinct from compliance-driven crypto standards.
What is (perfect) forward secrecy? Explain how it prevents retroactive decryption after a long-term key is compromised, which protocols provide it by default, and situations where it might be impractical to use.
Sample Answer
Direct answer
(Perfect) forward secrecy (PFS) means that even if an attacker later obtains a party's long-term private key, they cannot decrypt session traffic recorded in the past, because each session used its own ephemeral key that was discarded and is never derivable from the long-term key alone.
How it works
Instead of using the long-term private key directly to encrypt or derive the session key, each session performs a fresh (EC)DHE key exchange: a temporary key pair generated once and destroyed after the handshake. The session key is a function of that ephemeral exchange, not of the long-term key, so having the long-term key later gives an attacker nothing about past sessions.
Why static RSA key exchange lacks it
In an RSA key-transport handshake, the client encrypts the actual session secret directly under the server's long-term RSA public key. If an attacker records the ciphertext today and steals the server's private key years later, they can decrypt every recorded session, because the same long-term key that identifies the server also directly protects every session's secret, forever.
Which protocols provide it by default
TLS 1.3 mandates an ephemeral (EC)DHE exchange for every handshake, so forward secrecy is not optional. TLS 1.2 only gets it if the negotiated cipher suite uses ECDHE/DHE (a suite name containing "ECDHE" or "DHE"), so a TLS 1.2 server can still be misconfigured to prefer static RSA key exchange and silently lose it. Signal's Double Ratchet, SSH's default key exchange, and most modern VPN protocols (WireGuard, IKEv2 with PFS enabled) also provide it by design.
Situations where it can be impractical
Systems that need to decrypt archived traffic for legitimate reasons (regulatory replay, intrusion forensics, some enterprise deep-packet-inspection appliances) work directly against forward secrecy, since those use cases need a durable way to reconstruct the session key later, exactly what forward secrecy prevents. Some legacy hardware load balancers and older embedded TLS stacks also could not do the ephemeral key-exchange computation cheaply enough at their required connection rate, though that has become a weaker excuse as ECDHE has gotten cheap.
Worked example
If an adversary records encrypted VPN traffic today and compromises the VPN gateway's private key three years from now, whether they can retroactively decrypt today's traffic depends entirely on whether the key exchange used was ephemeral (safe) or static (exposed). This is the same "harvest now, decrypt later" pattern seen in the post-quantum threat discussion, just with a stolen private key as the trigger instead of a future quantum computer.
Trade-offs and pitfalls
A cipher suite name containing "RSA" alone (not "ECDHE_RSA") signals static key exchange with no forward secrecy, even though RSA can still be doing the authentication (signing) in the ECDHE_RSA case; do not confuse RSA-for-authentication with RSA-for-key-exchange. Forward secrecy protects past sessions from a future key compromise; it does nothing against an attacker actively controlling the connection right now, which is what authentication and integrity are for.
Describe the purpose of a salt in password-based key derivation: what properties it needs (uniqueness, length, randomness), where it should be stored relative to the derived hash, and the operational risks of reusing or omitting it at scale. Then explain the difference between a salt and a pepper: how does adding a server-side secret pepper change the threat model for offline attacks, and what controls does protecting a pepper actually require?
Sample Answer
Direct answer
A salt is a unique, random, non-secret value stored alongside each password hash so identical passwords never produce identical stored hashes and precomputed lookup tables (rainbow tables) become useless. A pepper is a separate, secret value, shared across all users and stored outside the database, that adds a layer an attacker who only stole the database, and not the pepper's separate storage, cannot reproduce at all.
Salt properties
- Uniqueness: every stored hash gets its own salt, so no two hashes can ever be compared or looked up in a shared precomputed table, even if two users chose the same password.
- Length and randomness: generated fresh with a cryptographically secure random number generator, long enough (16 bytes is a common minimum) that collisions across an entire user base are effectively impossible.
- Storage: the salt is not secret and is stored right alongside the derived hash, often concatenated into the same stored string as most KDF libraries' output format does, because verification needs it: a login attempt cannot be checked without knowing which salt was used.
Operational risks of reusing or omitting a salt at scale
Reusing one salt across many users collapses back to the pre-salt world for that group: identical passwords produce identical hashes again, so one cracked hash cracks every account sharing that password. Omitting a salt entirely makes precomputed rainbow-table attacks viable against an entire user base at once, and is the single most common real-world password-storage mistake salting exists to prevent.
Salt vs pepper
A pepper adds an ingredient a salt deliberately lacks: it is the same value for every user, unlike a salt, and it is never stored in the same place as the password hashes, typically in application configuration, a secrets manager, or a hardware security module (HSM), specifically so that a database breach alone, a SQL injection or a stolen backup, does not hand an attacker everything needed to attempt offline cracking.
How a pepper changes the threat model
Without a pepper, stealing the password-hash database is sufficient to start an offline brute-force or dictionary attack immediately. With a pepper, the attacker also needs to compromise wherever the pepper is stored, a genuinely separate system with its own access controls, before offline attacks become possible at all; a database-only breach becomes far less immediately damaging.
Controls a pepper actually requires
A pepper only helps if it is genuinely harder to steal than the database: its own access control (ideally an HSM/KMS-backed secret, not an environment variable sitting next to application code that also has database access), its own rotation plan (rotating a pepper means re-verifying and re-deriving every stored hash, a real migration, not a config change), and monitoring, since a pepper stored in the same place, or reachable via the same compromise path, as the database it protects provides no real additional security at all.
What is a Key Management Service, and what does the full key-management lifecycle look like for symmetric and asymmetric keys in an enterprise environment? For each stage (generation, provisioning, storage/usage, rotation, revocation, archival, secure destruction), name concrete controls and automation options you'd expect a KMS or HSM to provide, and the audit/logging you'd want at each stage. Compare cloud-managed KMS, HSM-backed KMS, and self-hosted key stores (like HashiCorp Vault) from an operational and decision-criteria standpoint: when would you reach for each?
Sample Answer
Direct answer
A key-management service (KMS) generates, stores, and controls the use of cryptographic keys without ever handing raw key material to the applications that use it: applications send data (or a wrapped key) and get back a result, never the key itself. Whether that KMS is a cloud-managed service, an on-premises hardware security module (HSM), or a self-hosted secrets manager is a decision about who controls the boundary the key never crosses, not about whether encryption happens.
The key lifecycle, stage by stage (the stages are the same for symmetric and asymmetric keys; only the storage/usage operations differ)
| Stage | What happens | Controls and automation | Audit and logging |
|---|---|---|---|
| Generation | Key material is created with a cryptographically secure random number generator, ideally inside the HSM/KMS boundary | Hardware random-number generator inside the HSM; enforced key-length/algorithm policy | Who requested generation, for what purpose, and the resulting key identifier and version |
| Provisioning | The key is made available to authorized services | Access policy binding the key to specific roles/services (least privilege); for asymmetric keys, distributing only the public half where possible | Every policy grant or change |
| Storage and usage | The key sits encrypted at rest, often wrapped by a KMS/HSM master key, and is used via API calls (encrypt/decrypt/sign/verify) rather than exported | Usage restricted to specific operations (a signing key that can only sign, never decrypt); rate limiting and anomaly detection on usage volume | Every single use: caller identity, operation, timestamp, and key version |
| Rotation | The active key is periodically replaced by a new version while old versions remain available to decrypt or verify data they already protected | Automated rotation schedules; for symmetric data-encryption keys, a key-encryption-key hierarchy so rotating the top key does not require touching the data | Rotation events and which version range remains valid for verification |
| Revocation | A key is marked untrusted before its normal retirement, typically on suspected compromise | Immediate propagation to every relying party's trust/verification list | Revocation reason, initiator, and propagation confirmation across systems |
| Archival | Retired keys are kept, encrypted, for as long as needed to decrypt or verify historical data, but are no longer used for new operations | Read-only access policy; a separate, more restrictive storage tier | Every archival access, since it is rarer and more suspicious by default |
| Secure destruction | Key material is irrecoverably deleted; cryptographic shredding is often the practical version of "destroying" data you cannot otherwise find and erase | Dual control (two-person authorization) before permanent deletion; a mandatory waiting or appeal window | The destruction request, dual-control approvals, and a permanent record that the key existed and was destroyed on a given date |
Comparing the three approaches
| Option | Where the key boundary lives | Best when |
|---|---|---|
| Cloud-managed KMS | Inside the cloud provider's infrastructure; you control policy, not physical hardware | You want low operational overhead and tight integration with the rest of a cloud provider's services, and accept its shared-responsibility model for the hardware layer |
| HSM-backed KMS | A dedicated hardware module, often validated against FIPS 140-3 (the current U.S. federal cryptographic-module standard; FIPS 140-2 certificates move to historical status by September 2026) | Regulatory or contractual requirements demand a specific, auditable hardware assurance level, or you need "hold your own key" control where the provider never sees the key at all |
| Self-hosted key store (for example HashiCorp Vault) | Entirely within your own infrastructure | You need full control over the software stack and deployment model, operate outside a single cloud provider, or have requirements a shared multi-tenant service cannot satisfy, at the cost of owning the operational burden yourself |
Worked example
A data platform storing per-tenant records typically holds a small number of key-encryption keys in the KMS/HSM (one or a handful per tenant, or a shared key with per-tenant data-encryption keys) and generates a fresh data-encryption key per object or per batch; only that small key ever needs to be sent to the KMS to unwrap, so the KMS's per-operation cost stays proportional to the number of distinct data-encryption keys, not the volume of underlying data.
Trade-offs and pitfalls
Do not conflate "we use a cloud KMS" with "we have a FIPS 140-3 validated system": the certification applies to a specific hardware/firmware module at a specific validation level (1 through 4), not automatically to every service built on top of it or to your own key-management practices. The most common real-world gap is not choosing the wrong option above, it is under-provisioning the audit-logging stage: if you cannot answer who used a key, when, and for what, after the fact, the KMS choice does not matter.
Explain the cryptographic differences between RSA key exchange and ECDHE (Elliptic Curve Diffie-Hellman Ephemeral) in TLS. Specifically, how does each impact perfect forward secrecy, and what are the consequences if the server's long-term private key is later compromised? What server configuration changes would you make to prioritize forward secrecy, and why?
Sample Answer
Direct answer
Static RSA key exchange lets the client encrypt the actual session secret directly under the server's long-term RSA public key, so anyone who later obtains the server's private key can decrypt every session ever recorded under it. ECDHE generates a fresh, temporary elliptic-curve Diffie-Hellman key pair for every handshake and derives the session key from that ephemeral exchange instead, so the server's long-term key never directly touches the session secret, and stealing it later reveals nothing about past sessions, which is exactly what forward secrecy means.
Mechanics
- RSA key exchange: the client generates a random pre-master secret, encrypts it with the server's RSA public key taken from its certificate, and sends it over. Only the private key can decrypt it, so this both establishes the shared secret and implicitly authenticates the server, but one long-term key is doing both jobs for every session, forever.
- Elliptic-Curve Diffie-Hellman Ephemeral (ECDHE): the server generates a fresh elliptic-curve key pair for this handshake only, sends the public half, and the client does the same; both sides compute the same shared secret from their own private half and the other's public half via elliptic-curve Diffie-Hellman. The server's long-term certificate key is used separately, only to sign the handshake and prove identity, never to encrypt the shared secret directly.
Impact on forward secrecy
RSA key exchange has none: the pre-master secret is only ever protected by the server's one long-term private key, so compromising that key at any later point retroactively exposes every session ever recorded that used it. ECDHE provides forward secrecy by construction: each session's ephemeral key pair is generated fresh and discarded after the handshake, so it is never derivable from the long-term signing key, and a future compromise of that key reveals nothing about past sessions' ephemeral keys, which no longer exist anywhere to be recovered.
Consequences of a later server private-key compromise
- Under RSA key exchange: catastrophic and retroactive. An adversary who recorded encrypted traffic at any point in the past and later obtains the private key can decrypt all of it, precisely the harvest-now-decrypt-later pattern.
- Under ECDHE: the compromised long-term key lets an attacker impersonate the server going forward, since they can now sign a fraudulent handshake and pass authentication, which is serious, but it does not expose any previously recorded session traffic, since that traffic's confidentiality never depended on the long-term key in the first place.
Server configuration changes to prioritize forward secrecy
- Remove RSA key-transport cipher suites from the server's negotiated suite list entirely rather than merely deprioritizing them, since a downgrade-capable client or a misconfigured negotiation could otherwise still select the weaker option.
- Prefer, and where the deployment allows it require, TLS 1.3, which removes static RSA key exchange from the protocol entirely, so this class of misconfiguration cannot happen at all rather than merely being avoided through careful cipher-suite ordering in TLS 1.2.
- If TLS 1.2 must still be supported for compatibility, explicitly configure the cipher-suite priority list so ECDHE-based suites are preferred over any suite offering only static RSA key transport. Note that RSA can still appear in an ECDHE suite name as the signature algorithm, for example ECDHE_RSA, which is fine, since only the key-exchange component matters here. Periodically re-verify the live negotiated configuration with an external TLS scan, not just a config-file review, since server software upgrades or configuration drift can silently reintroduce a deprioritized suite.
Trade-offs and pitfalls
Separate which part of the exchange the server's long-term key is doing, encrypting the actual session secret versus just signing a proof of identity, since that distinction is exactly where the forward-secrecy guarantee lives or does not. Simply deprioritizing a weak cipher suite in a configuration file is not the same guarantee as the protocol removing it entirely; treat TLS 1.3 adoption as the more durable fix.
Explain the differences between symmetric and asymmetric encryption. For each category, name two concrete algorithms you have used or implemented in production, describe typical system-level use cases (data at rest, key exchange, digital signatures), and discuss the performance, key-distribution, and operational trade-offs that push you toward one over the other. Where does envelope encryption and hardware-backed key storage fit into that choice?
Sample Answer
Direct answer
Symmetric encryption uses one shared secret key for both encrypting and decrypting (for example AES-256-GCM or ChaCha20-Poly1305): it is fast and cheap per byte, but both sides must already possess the same key. Asymmetric encryption uses a mathematically linked key pair, a public key anyone can hold and a private key only the owner holds (for example RSA-2048/3072 or elliptic-curve schemes like ECDH/Ed25519): it is orders of magnitude more expensive per byte, but it solves the problem of getting a shared secret to a party you have never met, and it enables digital signatures. Production systems almost never pick one exclusively; they combine both in a hybrid, envelope-encryption pattern.
Symmetric algorithms and use cases
- AES-256-GCM: an Advanced Encryption Standard (AES) block cipher run in Galois/Counter Mode (GCM), which gives you encryption and a built-in authentication tag in one pass. This is the default choice for encrypting data at rest: database columns, object storage, backups.
- ChaCha20-Poly1305: a stream cipher paired with a message-authentication code, popular where hardware AES acceleration is not available or reliable (some mobile chipsets) or where constant-time behavior in pure software matters. It is one of the two cipher suites every modern Transport Layer Security (TLS) 1.3 stack must support.
Asymmetric algorithms and use cases
- RSA (2048 or 3072-bit modulus): used for digital signatures (RSA-PSS) and, historically, for wrapping a symmetric key during key exchange. It is being phased out for key exchange because it provides no forward secrecy by default.
- Elliptic-Curve Diffie-Hellman Ephemeral (ECDHE), typically over curve X25519 or P-256: the workhorse of modern key exchange. A fresh key pair is generated per session and discarded afterward, which gives forward secrecy: compromising the server's long-term identity key later does not expose past session traffic.
Where each shows up
- Data at rest: symmetric (AES-256-GCM), because you encrypt large volumes repeatedly and asymmetric operations at that scale would be prohibitively slow.
- Key exchange: asymmetric (ECDHE, or historically RSA), because the two parties do not share a secret yet.
- Digital signatures: asymmetric (RSA-PSS or ECDSA/EdDSA), because only a private-key holder should be able to produce a valid signature that anyone with the public key can verify, which symmetric algorithms cannot do (both sides hold the same secret, so either could have produced it).
Worked example: why you cannot just use RSA for everything
RSA with Optimal Asymmetric Encryption Padding (OAEP) can only encrypt messages up to a fixed size, given directly by the padding scheme's own specification:
mLen≤k−2hLen−2
where k is the RSA modulus size in bytes and hLen is the padding hash's output size. For RSA-2048 (k = 2048/8 = 256 bytes) with SHA-256 padding (hLen = 32 bytes):
190=256−2(32)−2
A single RSA-2048 operation can protect at most 190 bytes directly, nowhere near enough for a 1 KB file, let alone a multi-gigabyte backup. That is the concrete reason production systems use envelope encryption instead of asymmetric encryption directly on bulk data.
Where envelope encryption and hardware-backed storage fit
Envelope encryption resolves that mismatch: generate a random symmetric data-encryption key (DEK), use it to encrypt the actual data with AES-256-GCM (fast, no size-limit problem), then encrypt (wrap) that small DEK with a separate key-encryption key (KEK) that never leaves a hardware security module (HSM) or a cloud key-management service (KMS). The wrapped DEK is stored next to the ciphertext; decrypting sends only the small wrapped DEK to the KMS/HSM to unwrap (one cheap operation), then does the bulk decryption locally. Hardware-backed storage matters because the KEK, whose compromise would expose every DEK it ever wrapped, is generated and used inside a tamper-resistant boundary designed to never export raw key material, so a compromised application server can ask the HSM to perform operations but cannot exfiltrate the key itself, and every such operation can be audited and rate-limited.
Trade-offs and pitfalls
- Performance: this is the trade-off the worked example above quantifies directly. Symmetric operations process bulk data at native memory speed with hardware acceleration; a single asymmetric operation like RSA-2048-OAEP costs orders of magnitude more per byte and, as shown, can only touch 190 bytes at a time, which is precisely why performance-sensitive systems route bulk work through the symmetric side of the hybrid design.
- Key distribution: symmetric-only designs need every pair of communicating parties to share a secret in advance, which does not scale (N parties need on the order of N-squared pairwise keys); asymmetric key exchange scales linearly because a public key can be published openly.
- Operational and security-level scaling: asymmetric key sizes must grow much faster than symmetric ones for equivalent strength; roughly, matching AES-128's strength needs an RSA modulus around 3072 bits, and matching AES-256 needs a modulus in the tens of thousands of bits, which is why elliptic-curve schemes (far smaller keys for equal strength) have displaced RSA for key exchange, and why operating a large RSA-based public key infrastructure carries more certificate and bandwidth overhead than an equivalent elliptic-curve one.
- Never hand-roll a mode: use a vetted library's authenticated modes (AES-GCM, ChaCha20-Poly1305) rather than composing an unauthenticated cipher yourself; unauthenticated ciphertext is silently malleable.
Unlock Full Question Bank
Get access to all 8 Applied Cryptography and Key Management interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.