Data Protection and Encryption in Practice Questions
Protecting data at rest and in transit across real systems from an engineering rather than pure-cryptography standpoint. Covers encryption strategy and key management for stored and transmitted data, secrets and sensitive-data handling, tokenization and secure elements for payment and sensitive data, and secure data handling in application code. Applied data-protection controls, distinct from cryptographic primitive design and from privacy-regulation compliance.
Describe the TLS handshake at a high level and explain how it protects data in transit. As someone reviewing a web server's configuration, which specific checks would you perform: cipher suites, supported protocol versions, certificate validation, and renegotiation behavior?
Sample Answer
Direct answer: TLS (Transport Layer Security, the protocol that encrypts and authenticates traffic between a client and a server) protects data in transit by having the client and server agree on a shared secret key over a public network without ever sending that key in the clear, then encrypting everything that follows with it. Reviewing a server's configuration means checking four things: which cipher suites (the specific combination of algorithms used for key exchange, encryption, and integrity checking) are enabled, which protocol versions are allowed, whether certificate validation is strict, and whether renegotiation is handled safely.
Structured elaboration:
The handshake, at a high level. First, the client sends a ClientHello proposing a TLS version and a list of cipher suites it supports. The server replies with a ServerHello picking a cipher suite from that list, plus its certificate, which proves its identity by being signed by a certificate authority the client already trusts. Both sides then derive a shared symmetric session key through a key exchange, most modern TLS uses a Diffie-Hellman-based exchange, which lets both sides compute the same secret from public values even though an eavesdropper sees those same public values. Finally, both sides confirm the handshake wasn't tampered with, and every message after that point is encrypted with the shared session key. TLS 1.3 compresses this into fewer round trips than TLS 1.2, but the underlying shape, agree on parameters, exchange keys, confirm, then encrypt, is the same.
What to check when reviewing a server's configuration. Cipher suites: disable legacy or weak suites, anything using RC4, 3DES, or export-grade cryptography, or that lacks forward secrecy (a property where each session uses a fresh key, so stealing the server's long-term key later cannot decrypt past recorded traffic), and prefer AEAD (authenticated encryption with associated data, a cipher mode that encrypts and checks integrity in one step) ciphers such as AES-GCM. Protocol versions: disable SSLv3, TLS 1.0, and TLS 1.1; require TLS 1.2 as a floor and prefer TLS 1.3 wherever every supported client can use it. Certificate validation: confirm the certificate chains to a trusted root, hasn't expired, and its subject or SAN (Subject Alternative Name, the field listing which hostnames a certificate is valid for) actually matches the hostname being served, and confirm revocation checking via OCSP or a certificate revocation list is configured, since an expired-but-unchecked certificate is a common gap. Renegotiation: TLS renegotiation is a client or server re-running the handshake on an already-open connection to refresh keys or parameters; disable client-initiated renegotiation, or at minimum ensure secure renegotiation is enforced, since insecure renegotiation was the root of a well-known man-in-the-middle class of attack against older TLS deployments.
Certificate validation in practice means checking the whole trust chain, not just the leaf certificate: the chain runs from the server's own certificate up through one or more intermediate certificate authorities to a root the client already trusts, and a server that omits an intermediate certificate will fail validation for clients that don't already cache it, even though the leaf certificate itself is fine. Mutual TLS, or mTLS, where both sides present a certificate rather than just the server, is called for when you need cryptographic proof of the client's identity too, which is the normal case for service-to-service traffic inside a zero-trust network, or for a business-to-business API where you want to authenticate the calling organization by certificate rather than, or in addition to, an API key.
Worked example: A server offering TLS 1.0 alongside TLS 1.3, with a cipher list that still includes a 3DES suite, and no OCSP stapling configured, fails this review on three of the four checks: drop TLS 1.0 and the 3DES suite, and add OCSP stapling, where the server proactively attaches revocation-status proof to its own handshake instead of making every client query the certificate authority separately.
Trade-offs and pitfalls: Disabling old protocol versions and weak ciphers can break traffic from clients that genuinely can't be upgraded, some older devices only speak TLS 1.0. That's usually still the right trade to make, but it needs to be a deliberate, communicated decision rather than a surprise outage.
What is format-preserving encryption, and what problem does it solve that standard symmetric encryption modes do not? Name common approaches and explain the security trade-offs involved in preserving format.
Sample Answer
Direct answer
Format-preserving encryption (FPE) is a mode of encryption that produces ciphertext in exactly the same format as the plaintext, the same character set and length, so encrypting a 16-digit credit card number produces another 16-digit number rather than the binary-looking blob standard modes like AES-GCM produce. It solves the problem of encrypting data that has to keep flowing through rigid legacy schemas, database columns, and validation rules that a normal ciphertext blob would break.
Structured elaboration
The problem it solves. Many legacy systems, database columns typed as a fixed-length numeric field, or downstream validators expecting a specific pattern, weren't built to accept an arbitrary-looking ciphertext. FPE lets you encrypt a value in place without changing the schema or touching every consumer of that field, simply because the output still "looks like" valid data of the same shape.
Common approaches. The standardized constructions are FF1 and FF3-1 (both defined in NIST's FPE standard), which build a Feistel-network cipher on top of a standard block cipher, typically AES, restricted to operate over a small alphabet, such as the digits 0 through 9, instead of raw bytes. FF3-1 is a corrected revision of an earlier version, FF3, after a published weakness was found in the original tweak handling, so FF3-1 is the one that remains recommended.
Security trade-offs of preserving format. The value is still protected by the underlying 128-bit AES key, so FPE's reduced security margin does not come from a weaker key. For a fixed key and tweak, FF1 and FF3-1 are keyed bijections (permutations) over the set of valid inputs, so there is no oversized output blob and no output collisions to search for. The weakness comes instead from the size of that input set, the domain. Two things degrade as the domain shrinks. First, the provable-security bounds of a small-domain Feistel construction are weaker than those of a full-width block cipher, because a Feistel network over a tiny alphabet has little room to mix and hide its structure. Second, there are concrete domain-size-dependent attacks: the Durak-Vaudenay attack that broke the original FF3 (and motivated the FF3-1 revision) recovers the permutation with a work factor that scales polynomially in the domain size, so it becomes practical precisely when the domain is small. This is why applying FPE to a short, low-entropy format such as a four-digit PIN is considered particularly weak, while applying it to a long value is comparatively safe.
Worked example
Because the security concern is the size of the domain, not the AES key, the right quantity to compare is how many values an attacker would have to enumerate to defeat the scheme for a given key and tweak. FPE is a bijection over that domain, so an attacker with chosen-plaintext access can query every possible input once and build the complete plaintext-to-ciphertext table, fully inverting the scheme without ever attacking AES. The cost of that codebook attack is just the domain size:
pin4_domain = 10 ** 4 # a 4-digit PIN
card16_domain = 10 ** 16 # a 16-digit card number
# A keyed bijection can be fully mapped with one chosen-plaintext query per value.
print(f"4-digit PIN: {pin4_domain:,} values to enumerate")
print(f"16-digit card: {card16_domain:.0e} values to enumerate")
print(f"The PIN domain is {card16_domain // pin4_domain:.0e}x smaller")
Output:
4-digit PIN: 10,000 values to enumerate
16-digit card: 1e+16 values to enumerate
The PIN domain is 1e+12x smaller
Ten thousand values is trivially exhaustible: an attacker who can obtain ciphertexts for chosen PINs reconstructs the entire mapping in at most 10,000 queries, and even without an oracle a domain that small is vulnerable to frequency analysis and to the domain-scaling recovery attacks that make small-domain FPE weak. The same codebook attack against the 16-digit format would need 10^16 queries, which is infeasible, so the 16-digit case is not the weak one. The lesson is the opposite of a raw key-size comparison: FPE gets riskier as the format gets shorter, so it should never be used to protect a short, low-entropy field like a PIN.
Trade-offs and pitfalls
FPE should be reserved for genuine legacy or format-compatibility constraints, not chosen by default just because it's convenient to bolt onto an existing schema. Where no such constraint exists, a standard mode with its much larger security margin is the better default.
Design encrypted backups for a production database such that the backups remain confidential, are recoverable even after a key-loss event, and support point-in-time restore across regions. Cover where key material is stored relative to the backup, what backup metadata you need, and how you would test that a restore actually works.
Sample Answer
Direct answer
Wrap each backup's data key with a key held in a KMS (Key Management Service) or HSM (Hardware Security Module), but the design constraint that actually matters is keeping a break-glass path to that wrapping key that survives a failure independent of your normal operations, otherwise "encrypted backup" quietly becomes "permanently destroyed backup" the moment the primary key becomes unavailable.
Structured elaboration
Where key material lives relative to the backup: Never store the unwrapped data key, or the wrapping key itself, alongside the backup data; an attacker or ransomware actor who gets both at once gets a fully usable copy. Keep KMS- or HSM-held keys in a separate account, region, or trust boundary from backup storage, and maintain a genuine disaster-recovery path for the wrapping key itself, for example a multi-region replica key in a cloud KMS, or a documented, sealed physical key-recovery procedure, for scenarios where the primary key management system is itself unavailable or deleted.
Backup metadata needed: Record which key ID and key version wrapped this specific backup, since keys rotate over a backup's retention period and an old backup can only be restored with the historical key version that actually protected it. Also record a timestamp, source region, and a checksum of the plaintext for restore verification, plus enough catalog information to locate the correct backup for a point-in-time restore into a target region without decrypting every candidate just to check.
Cross-region point-in-time restore: Replicate the encrypted backup (still ciphertext) to the target region, and separately ensure the wrapping key is usable there too, for example through a multi-region KMS key. Shipping ciphertext without shipping (or re-wrapping for) the corresponding key access leaves an unreadable backup in the new region.
Testing that restores actually work: Schedule regular, automated restore drills that decrypt a real backup and validate it at the application level, row counts, checksums, a smoke-test query, rather than trusting a "backup completed" status, which only proves bytes were written and encrypted, not that they can be read back. Specifically test the disaster path, restoring via the break-glass key procedure, not only the everyday path, since the break-glass path is the one most likely to have quietly rotted from disuse.
Worked example
A nightly database snapshot is encrypted with a data key, which is itself wrapped by KMS key K1 at its current version, version 3. The backup object is stored with metadata {key_id: K1, key_version: 3, checksum, timestamp}, and replicated to a second region where K1 exists as a multi-region replica key. Because K1 rotates quarterly, a monthly restore drill deliberately pulls a backup from six months earlier, wrapped under K1 version 1, and confirms that version is still resolvable and the restore completes end to end, not just the most recent backup under the current key version.
Trade-offs and pitfalls
A very common failure mode is a KMS key deletion, most cloud providers enforce a mandatory waiting period before a scheduled key deletion completes specifically as a safety net, triggered by unrelated cleanup automation that silently orphans every backup wrapped by that key. Treat key deletion as a rare, high-blast-radius, deliberately friction-heavy operation, and track which backups depend on a given key so one is never deleted while backups still reference it.
Propose a strategy for measuring and reporting the performance impact of encryption, CPU, memory, and network, across a heterogeneous fleet of VMs, containers, and serverless functions. How would you attribute observed latency to cryptographic operations rather than other causes?
Sample Answer
Direct answer
Measure the performance impact with a controlled, before/after or shadow-traffic comparison rather than reading raw fleet-wide averages, and attribute the delta specifically to cryptographic work using CPU profiling that names the actual cipher and handshake calls, not just an increase in end-to-end latency, since aggregate latency conflates cryptography with garbage collection, network queuing, and downstream service time.
Structured elaboration
Baseline comparison method: Where encryption can be safely toggled, for example TLS (Transport Layer Security) termination on versus off in a staging environment, or a canary with field-level encryption disabled versus enabled, hold every other variable constant and compare. Where production cannot safely disable encryption (usually the right call), replay synthetic or shadowed traffic against both configurations instead of touching production directly.
Fleet heterogeneity: VMs, containers, and serverless functions have very different baseline compute profiles and cold-start behavior, so a single blended average hides which platform is actually paying the cost. Measure cryptographic overhead as a relative delta per request or per operation, separately for each compute type, rather than one number across the whole fleet.
Attribution technique: Use CPU profiling (flame graphs) that can attribute time specifically to cryptographic library calls, for example time spent inside an AES-GCM encrypt call versus TLS handshake negotiation versus the rest of request handling, rather than inferring cryptographic cost purely from an aggregate latency increase. Check whether hardware crypto acceleration (AES-NI on the CPU, or a dedicated offload path) is actually enabled on each fleet, since the identical algorithm can look far more expensive on hardware that isn't using it, which is a configuration gap, not an inherent cost of encryption.
Serverless specifically: A cold start that has to call out to a KMS (Key Management Service) to unwrap a data key has a very different cost profile than a long-lived VM or container that keeps a decrypted key cached in memory. Report these separately; averaging them makes serverless look disproportionately "encryption-expensive" when the real cost is the KMS round trip on cold start, not the cipher itself.
Reporting: Report overhead as a relative delta against a clearly defined baseline and workload, not a bare absolute number, and break out CPU, memory, and network separately, since different mechanisms cost differently: TLS overhead is mostly CPU plus a small amount of network from handshake round trips, while a per-request KMS call is mostly network and external-service latency, not local CPU.
Worked example
One genuine, easily verified cost that doesn't require any benchmark at all is ciphertext expansion: AES-GCM (a standard authenticated encryption mode) adds a 12-byte nonce and a 16-byte authentication tag to every encrypted message, a fixed 28 bytes of overhead per message regardless of payload size. On a fleet moving small, frequent messages, that 28-byte expansion can itself explain part of an observed increase in network bytes transferred, independent of any CPU cost, and this is exactly the kind of decomposition a good attribution exercise should separate out: how much of the observed delta is genuinely cryptographic CPU work, how much is this fixed protocol overhead, and how much is an unrelated confound like a coincident garbage-collection change.
Trade-offs and pitfalls
The most common mistake is attributing an entire observed latency increase to "encryption" when a meaningful share is actually a downstream network hop or an unrelated change that happened to ship in the same release. The second most common is under-provisioning CPU: a hardware-accelerated cryptographic operation that looks nearly free on one instance type can become a real bottleneck once cores are saturated on another, making the same algorithm look expensive purely due to acceleration availability, not the algorithm itself.
Design a field-level encryption approach for a microservices architecture where specific PII fields, for example a social security number or email address, must be encrypted at the service boundary while some services still need to index or search on those fields. Cover deterministic versus randomized encryption, key-per-field versus key-per-tenant, and how you would handle schema versioning as encrypted fields change type or size.
Sample Answer
Direct answer
Encrypt PII (personally identifiable information) fields like a social security number or email address at the service boundary, wrapping a per-field data key with a key from a central KMS (Key Management Service), and choose deterministic encryption only for the specific fields that must remain exactly searchable, randomized encryption for everything else, since randomized ciphertext reveals nothing about whether two values match.
Structured elaboration
Deterministic versus randomized: Deterministic encryption produces identical ciphertext for identical plaintext every time, which enables equality lookups and database joins, but leaks pattern information: anyone who can see the ciphertext column can tell which rows share a value, and frequent values become visible through simple frequency analysis. Randomized encryption (for example AES-GCM with a fresh random nonce each time) produces different ciphertext every time for the same plaintext, so no lookup is possible without decrypting, and no pattern leaks. Default to randomized; use deterministic only where a genuine business need for exact-match search exists on that specific field.
Key-per-field versus key-per-tenant: Key-per-field uses a separate data key for each field type (one for SSNs, another for emails) across all tenants, limiting the blast radius of a key compromise to one field type. Key-per-tenant uses one key hierarchy per tenant covering all of that tenant's fields, limiting blast radius to a single tenant, and it enables crypto-shredding: deleting a tenant's key instantly and irreversibly makes all of that tenant's encrypted data unreadable, which is a fast, reliable way to satisfy a tenant-offboarding data-deletion requirement without a slow row-by-row delete job.
Where decryption happens: Decrypting inside the calling application, using a shared internal library, keeps the database and any database proxy from ever seeing plaintext, and centralizes the crypto logic so individual teams don't reimplement it insecurely. Decrypting at a database-proxy layer (a sidecar sitting between the application and the database) centralizes crypto operations without requiring every service to integrate the library, but turns that proxy into a single high-value target that needs its own hardening. For most PII, application-layer decryption is the safer default; a proxy is a reasonable compromise for a large number of legacy services that can't easily be touched.
Library selection for a polyglot stack: The same field must decrypt correctly whether it was written by a Java service or read by a Python one, so pick a single, well-vetted, cross-language cryptographic library or specification, such as Google's Tink, rather than letting each team choose its own primitives independently, and verify that test vectors produce byte-identical ciphertext behavior across every language in use before relying on it.
Schema versioning: Attach a small header to every ciphertext recording the key ID and algorithm version used. When a field's encryption scheme changes, for example moving email from randomized to deterministic because a new search requirement appeared, run a background job that decrypts with the old key and version, re-encrypts with the new one, updates the version tag, and only then removes the old ciphertext. This allows field-by-field migration without a risky, all-at-once cutover.
Concrete field examples. Email is a strong candidate for deterministic encryption, since "does this email already exist" is a common exact-match check during signup. A credit card number generally should not be handled by this kind of general field-level encryption at all; it belongs in a dedicated tokenization flow with its own PCI-scoped vault, not the shared field-encryption path used for identifiers like email or SSN.
Worked example
A signup service receives { email, ssn }. The email field is encrypted deterministically with the tenant's per-tenant data key, so a later WHERE email = ? lookup at signup time works without decrypting every row. The SSN field is encrypted with a randomized scheme using the same tenant key, since nothing in the product needs to search on it, and its ciphertext changes every time even for the same value. Both data keys are themselves wrapped by a tenant-scoped key held in the central KMS, so revoking that tenant's access is a single key operation, not a per-field cleanup.
Trade-offs and pitfalls
Deterministic encryption on a low-cardinality field, a boolean flag or a two-digit country code, leaks almost the entire value through frequency analysis, since there are only a handful of possible ciphertexts to distinguish; never apply it there. Combining key-per-tenant encryption with a shared, cross-tenant search index also breaks isolation unless the index itself is scoped per tenant.
Unlock Full Question Bank
Get access to all 37 Data Protection and Encryption in Practice interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.