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.
You're starting a greenfield system expected to run for more than 10 years. List the factors you'd weigh when selecting cryptographic algorithms and key sizes for symmetric encryption, public-key encryption, signatures, and key exchange. How would you build in algorithm agility from day one, and how would you document these choices so a future team can safely migrate them?
Sample Answer
Direct answer: For a system meant to run 10+ years, do not just pick "the strongest algorithm available today." Pick current, NIST-recommended algorithms with a comfortable security margin, design the ciphertext and protocol formats so the algorithm itself is a swappable, versioned field rather than baked into the wire format, and write down every choice with its assumptions and a review date. Agility and documentation matter as much as the initial algorithm choice, because you cannot predict what will need to change in year 6.
Factors per primitive
- Symmetric encryption: use AES-256-GCM (or ChaCha20-Poly1305 where hardware AES acceleration is unavailable). Rationale: Grover's algorithm gives quantum computers a quadratic speedup against brute-force key search, so a key of length k bits gives only about k/2 bits of security against a quantum attacker. AES-128 would degrade to roughly 64-bit post-quantum security, too thin for a decade-plus horizon. AES-256 still leaves roughly 128-bit margin. This is the cheapest form of "future-proofing" available: symmetric algorithms do not need new math, just a bigger key.
- Public-key encryption / key exchange: classical RSA-2048 or ECC (elliptic-curve cryptography, the main alternative to RSA) (X25519, P-256) is fine against today's computers but carries zero quantum margin: Shor's algorithm breaks the underlying math outright rather than merely halving it. For anything that must stay confidential for a decade, this is the "harvest now, decrypt later" risk: an adversary records ciphertext today and decrypts it once a cryptographically relevant quantum computer exists. Architect for a hybrid classical-plus-post-quantum key encapsulation mechanism (KEM) from day one, even if you cannot deploy it yet, so the wire format already has a slot for it.
- Signatures: ECDSA P-256 or Ed25519 (both elliptic-curve signature schemes; Ed25519 is a solid modern default) today, but if the data or documents being signed need long-term non-repudiation (contracts, archival records), plan a migration path to a post-quantum signature and consider independent timestamping, since a signature's cryptographic strength only needs to hold up to the moment it is verified, but verification might happen decades later.
- Key exchange: always use ephemeral exchange (ECDHE/DHE, the elliptic-curve and classical variants of ephemeral Diffie-Hellman key agreement), never static, for forward secrecy. This has nothing to do with the quantum question and everything to do with limiting the blast radius of any future key compromise.
Building in algorithm agility
- Version every ciphertext, token, and certificate format with an explicit algorithm identifier and key-version field up front (the way TLS cipher suites or a JOSE
algheader work), never a fixed-width blob with an implicit algorithm. - Put crypto operations behind a narrow internal interface (a
Signer, aKeyExchange) so callers never depend on one library's concrete types directly. Swapping an implementation becomes a change behind that interface, not a project-wide find-and-replace. - Support the current and previous algorithm simultaneously during any migration window (dual-read, single-write for new data), never a hard cutover.
- Reuse a standard container format that already treats algorithm identity as first-class (X.509, JOSE/COSE, TLS) instead of inventing your own byte layout.
Documentation
- Keep a living cryptographic inventory (sometimes called a cryptographic bill of materials): every algorithm, key size, library, and where each is used.
- Write an architecture decision record for each choice capturing the threat model assumed and an explicit "review by" date (for example, tied to a known deprecation milestone such as NIST's phased retirement of 112-bit-security algorithms).
- Maintain, and actually rehearse, a migration runbook rather than leaving it as an untested design document.
Worked example. The Grover's-algorithm halving is the one number worth internalizing: a k-bit symmetric key gives roughly 2^(k/2) post-quantum brute-force operations. For AES-128, that is 2^64, within reach of a well-resourced, patient attacker even setting aside classical improvements. For AES-256, that is 2^128, comfortably out of reach for the foreseeable future. That single fact is why "use AES-256, not AES-128" is close to a free future-proofing decision, while the same logic does not rescue RSA or ECC, whose underlying math (factoring, discrete log) is broken outright by Shor's algorithm rather than merely weakened.
Trade-offs and pitfalls. A common wrong turn is defaulting to the mathematically largest option everywhere (RSA-4096 for every signature) without addressing agility: a bigger classical key buys you nothing against a quantum adversary and costs real performance. The opposite failure is designing "agility" as an open-ended plugin architecture supporting dozens of algorithm combinations; that makes testing and certification infeasible. Bound agility to a short, deliberately curated allow-list with a clear default, not an unbounded menu.
What is key wrapping, and how does it differ from both encrypting arbitrary data and deriving a key? Describe common key-wrapping algorithms (AES-KW/RFC 3394, AES-GCM wrapping), and explain why integrity/authentication and atomic unwrap semantics matter. In an envelope-encryption pattern, why do you wrap a data-encryption key with a key-encryption key instead of encrypting the data directly with the master key?
Sample Answer
Direct answer
Key wrapping is encrypting one key with another key so it can be safely stored or transmitted and later recovered exactly, a reversible operation on a specific piece of key material. That's different from encrypting arbitrary data, which handles payloads of any size and shape, and different from key derivation, which computes a new key from an input using a one-way function and never needs to be unwrapped back to anything, because there was no ciphertext to reverse in the first place, only a deterministic recomputation. In an envelope-encryption pattern, you wrap the data-encryption key with a key-encryption key rather than encrypting the data directly with the master key, because that keeps the expensive, often hardware-bound master key touching only a tiny, fixed-size blob instead of every byte of actual data.
Structured elaboration
Key wrapping versus encrypting arbitrary data
- Wrapping is purpose-built for a small, high-entropy, fixed-format blob, and the format constraints reflect that: classic AES-KW (RFC 3394) uses a fixed initialization value and no random nonce, because the input is already fully random key material, not user data that might repeat or carry low entropy, so it doesn't need the nonce-uniqueness protections general authenticated encryption needs for arbitrary payloads.
- General-purpose encryption such as AES-GCM on a data payload has to handle arbitrary length, needs a fresh nonce per encryption, and is optimized for throughput on potentially large inputs. Wrapping formats instead optimize for the narrower job of protecting one small secret and detecting any tampering with it.
Key wrapping versus key derivation
- Derivation, an HKDF-style function, takes an input key and produces new key material deterministically. There is no ciphertext to store and nothing to unwrap, the same input and parameters always reproduce the same output, a one-way, repeatable computation rather than a reversible transform on stored ciphertext.
- Wrapping produces ciphertext that must be stored, there is no way to recompute it later without that ciphertext, and unwrapping is the direct inverse of wrapping, recovering the exact original key bytes.
- A concrete tell: if losing the stored blob means the key is gone forever, that's wrapping; if the same key can always be regenerated from the same master secret and context, that's derivation. Both can appear in the same system, a master secret might derive several purpose-specific keys via HKDF, and one of those derived keys might then wrap a randomly-generated DEK for storage, but they solve different problems and are not interchangeable.
Common key-wrapping algorithms
- AES-KW (RFC 3394): wraps a key with AES in a specific chaining mode using a fixed initial value, which doubles as an integrity check on unwrap, since a corrupted or forged wrapped blob will very likely fail to reproduce the expected fixed value, giving implicit integrity without a separate MAC.
- AES-GCM wrapping: standard AES-GCM authenticated encryption with the key material as the plaintext, giving an explicit authentication tag rather than AES-KW's implicit check, and naturally supporting associated data, binding the wrap to the key's intended purpose or ID so a wrapped DEK can't be silently swapped for a different one with the same ciphertext bytes.
Why integrity, authentication, and atomic unwrap semantics matter
- If a wrapped key's ciphertext is corrupted or tampered with and unwrap doesn't detect that, you get a garbage "key" that silently produces wrong plaintext or wrong signatures instead of a clear failure, a much worse failure mode than an explicit error, since it can look like success while actually being wrong.
- Atomic unwrap means the operation either fully succeeds and returns the correct original key, or fully fails with no partial or corrupted key ever handed to the caller, a half-unwrapped key isn't a smaller version of the real key, it's an entirely different, wrong value a naive caller could mistake for legitimate.
Why wrap the DEK instead of encrypting data directly with the master key
- The master key is the highest-value, often hardware-bound asset, envelope encryption means it only ever touches small, fixed-size key blobs, never the bulk data, so its usage volume stays low and predictable regardless of how much actual data is being protected.
- Rotating the master key then only requires re-wrapping the small DEKs, a cheap operation since a DEK is typically 32 bytes, rather than re-encrypting potentially terabytes of underlying data, which is why almost every production system uses this pattern instead of encrypting data directly with a master key.
Worked example
If a service protects 10 million objects with envelope encryption and later rotates its master key, the rotation work is 10 million small DEK re-wrap operations, each a few hundred bytes at most, not 10 million object re-encryptions. If the average object is 5 MB, direct master-key encryption would mean re-encrypting roughly 10,000,000 times 5 MB, or 50 TB, on every rotation, versus re-wrapping roughly 10,000,000 times 32 bytes, or about 320 MB, of DEKs, a difference of more than five orders of magnitude in the work a rotation actually requires.
Trade-offs and pitfalls
Common wrong turn: treating key wrapping and key derivation as interchangeable ways to get a key from another key. Derivation can't recover a specific, previously-generated value, a randomly generated DEK you need back exactly has to have been wrapped and stored, not re-derived. Common wrong turn: rolling a custom wrap format instead of using AES-KW or AES-GCM wrapping, a bespoke format is exactly where integrity and atomic-unwrap guarantees quietly go missing. Senior signal: explaining envelope encryption in terms of what it protects, the master key's usage volume and rotation cost, rather than describing it only as a two-layer encryption scheme.
What assurances and features does a Hardware Security Module (HSM) provide for key management and cryptographic operations (tamper resistance/evidence, FIPS assurance levels, secure key generation, sealed storage, key wrapping, attestation)? How does that change operational practice compared to a software-only key store, and when do you actually need dedicated hardware rather than a cloud KMS, a Kubernetes secret store, or a self-hosted vault?
Sample Answer
Direct answer
An HSM's value is that key material is generated, used, and stored inside a certified, tamper-evident hardware boundary and never has to leave in plaintext form. A software-only key store can protect keys with access control and encryption, but the bytes still exist somewhere a sufficiently privileged process or root-level attacker can eventually read. You reach for dedicated hardware specifically when you need that non-extractability guarantee for compliance or blast-radius reasons, not for general secret storage, where a cloud KMS, a Kubernetes secret store, or a self-hosted vault is usually the right, cheaper answer.
Structured elaboration
What an HSM actually provides
- Tamper resistance and evidence: physical construction (potting, mesh sensors, voltage and temperature monitors) designed to destroy key material, or at minimum show visible evidence of intrusion, if the device is opened or attacked, rather than relying only on software access control.
- FIPS assurance levels: HSMs are commonly validated to FIPS 140-3, the current version of the standard (superseding FIPS 140-2), which defines four increasing levels. Level 1 requires only approved algorithms with no physical security requirement, Level 2 adds tamper evidence and role-based authentication, Level 3 adds tamper resistance and response with identity-based authentication and logical or physical separation between roles, and Level 4 adds environmental failure protection for hostile physical environments. Most production HSMs protecting high-value key material are validated to Level 3.
- Secure key generation: keys are generated inside the module using a validated, continuously health-tested random bit generator, not on a general-purpose host's less-scrutinized entropy pool.
- Sealed storage: private key material lives only inside the module's protected memory; even administrators typically cannot extract it, only invoke operations that use it.
- Key wrapping: keys can be securely exported in encrypted (wrapped) form for backup or transport to another HSM without ever existing in plaintext outside a hardware boundary.
- Attestation: the module can cryptographically prove its own identity and firmware state to a relying party, so trusting a given HSM instance with real key material doesn't rest on a vendor's claim alone.
How this changes operational practice compared to a software-only key store
- Every cryptographic operation becomes an API call to the module rather than reading a key into memory and computing locally, which changes both latency (a round trip per operation) and throughput planning (an HSM has a rated operations-per-second ceiling to capacity-plan against).
- Backup and disaster recovery require HSM-to-HSM wrapped export and import, or a quorum-based recovery ceremony, not a simple encrypted file copy.
- Compliance evidence gets much cleaner: "the key never left a FIPS-validated boundary" is a specific, auditable claim a software key store cannot make no matter how well access-controlled it is.
When you actually need dedicated hardware rather than a cloud KMS, a Kubernetes secret store, or a self-hosted vault
- A regulation or contract names FIPS 140-3 (or a specific level) or a hardware security boundary explicitly, common in payments, government, and parts of healthcare and finance.
- The key protects something catastrophic if extracted, a root CA key, a code-signing key, a payment HSM's PIN-block key, where the cost of dedicated hardware is small relative to that key's blast radius.
- You need non-extractability guaranteed even against a cloud provider's own privileged operators, a stronger, directly auditable boundary than most managed-KMS tiers offer, though many providers' hardware-backed tiers get close.
- A cloud KMS is the right default otherwise, giving most of the operational assurance without owning physical hardware and at dramatically lower cost and complexity.
- A Kubernetes secret store or self-hosted vault is right for general application secrets, database passwords, API tokens, that don't need hardware-bound non-extractability, forcing those through a dedicated HSM adds latency and cost with no matching risk reduction.
Worked example
A payment processor signing transaction authorizations needs that signing key to never exist outside FIPS 140-3 Level 3 hardware, because a leaked signing key would let an attacker forge authorizations indefinitely, so it uses a dedicated payment HSM. The same company's database credentials for a few dozen known internal services, rotated weekly, don't carry that blast radius; a cloud KMS or a self-hosted vault issuing short-lived dynamic credentials is the appropriate, far cheaper choice, and routing those through a payment HSM would add operational friction without reducing real risk.
Trade-offs and pitfalls
Common wrong turn: defaulting to "we should use an HSM" for every secret because it sounds more secure, when the actual risk being defended against doesn't need hardware non-extractability, needlessly adding cost, latency, and complexity. Common wrong turn: assuming a vendor's FIPS 140-3 validation on its overall product line automatically covers your specific configuration, validations are scoped to specific hardware, firmware version, and operating mode, so confirm the validated configuration actually matches what you deploy. Senior signal: naming the specific guarantee, non-extractability, attested firmware identity, sealed generation, rather than reaching for "HSM equals more secure" as an unexamined default.
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.
Describe the core components and trust model of an enterprise Public Key Infrastructure: root CA, intermediate CAs, issuing CAs, certificate profiles and validity periods, registration authorities, and the strategies (offline root, short-lived certs, cross-certification) used to limit blast radius if a CA is compromised. Then walk through what actually happens end to end for one certificate: how it's requested and issued (CSR, CA validation), how a client validates the resulting chain (chain verification, hostname checks), and how automated issuance (e.g. Let's Encrypt / ACME) changes that story at scale.
Sample Answer
Direct answer
A production public key infrastructure (PKI) is a tree of trust: an offline root certificate authority (CA) signs one or a few intermediate CAs, which in turn sign the issuing CAs that actually hand out end-entity certificates. Nobody trusts an end-entity certificate directly; they trust it because it chains up to a root their software already trusts.
Trust model and components
- Root CA: the ultimate trust anchor, pre-installed in operating systems' and browsers' trust stores. Because compromising it would let an attacker mint a trusted certificate for anything, it is kept offline (air-gapped, powered on only to sign new intermediates) and used as rarely as possible.
- Intermediate CA: signed by the root, does the actual day-to-day signing directly or through issuing CAs beneath it. Splitting root from intermediate means a compromised or misused intermediate can be revoked without touching the root already baked into every trust store, avoiding a mass client update.
- Issuing CA: the online intermediate (or sub-CA) that actually processes certificate requests. Large organizations often run separate issuing CAs per purpose (TLS server certs, code-signing certs, client-auth certs), so a problem in one issuing path does not force revoking every certificate type at once.
- Registration authority (RA): the component, sometimes separate, sometimes folded into the issuing CA, that verifies a requester actually controls the domain or identity being certified before the CA signs anything.
- Certificate profiles and validity periods: a profile defines the fields and extensions a given certificate type must carry (key usage, extended key usage, subject alternative names). Shorter validity periods shrink the window a compromised or mis-issued certificate stays dangerous: the CA/Browser Forum's baseline requirements capped public web TLS certificates at 398 days for years, but a phased reduction already dropped that ceiling to 200 days in March 2026, with 100 days due in March 2027 and 47 days by March 2029.
Limiting blast radius if a CA is compromised
- Offline root: the root's private key never touches a network-connected machine, so remote compromise of issuing infrastructure cannot reach it directly.
- Short-lived certificates: if certificates expire in days rather than years, a compromised issuing CA's damage window is bounded by how quickly you detect and revoke it, and even undetected mis-issuance ages out fast.
- Cross-certification: having two independent CAs certify the same intermediate, or maintaining alternate trusted paths, means a single CA's revocation does not instantly break every relying party, giving a rollover path instead of a hard outage.
End-to-end walkthrough for one certificate
- Request and issuance: the requester generates a key pair and a certificate signing request (CSR), a self-signed message asserting "I hold the private key matching this public key, and I am requesting a certificate for this identity." The RA/CA validates control of the domain (a DNS record, an HTTP file, or an out-of-band check) or identity, then the issuing CA signs the CSR's public key and identity into a certificate.
- Client validation: a client receiving the certificate walks the chain up to a trusted root (chain verification), checks the certificate has not expired or been revoked, and checks the hostname it connected to matches a name listed in the certificate (hostname/Subject Alternative Name check). Any one of those failing should hard-fail the connection.
- Automated issuance at scale: the Automatic Certificate Management Environment (ACME) protocol, used by Let's Encrypt and most modern CAs, replaces manual CSR handling with an API: the client proves domain control programmatically (an HTTP or DNS challenge) and gets a certificate issued and renewed automatically, often on a 90-day lifetime. This is what makes short-lived certificates operationally viable at scale; doing this by hand across a large fleet would be a full-time job, but ACME turns it into unattended automation.
Worked example
example.com's certificate might be signed by "Acme Issuing CA G2," which is signed by "Acme Intermediate CA," which is signed by the offline "Acme Root CA X1" baked into an operating system's trust store; verifying the chain means checking each of those two signatures in turn before trusting example.com at all.
Trade-offs and pitfalls
Relying only on the default trust-store setup without your own operational monitoring for renewal and revocation is exactly what causes expired-certificate outages. OCSP stapling (the server proactively attaches a signed revocation-status response) exists because live client-side OCSP lookups add latency and leak browsing metadata to the CA; understanding why matters more than memorizing the acronym.
Unlock Full Question Bank
Get access to all 24 Applied Cryptography and Key Management interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.