skip to content

Why is a 4 MB file never encrypted directly under an RSA public key, and what does the standard hybrid (envelope) construction do instead? Derive the size limit rather than quoting a number.

level: middleimportance: must knowfreq 60%

answer

  1. message must be smaller than the modulus
  2. modulus bytes minus padding overhead
  3. no mode of operation for public-key
  4. random data key: wrap the key, not the data
  5. key id in the envelope enables rotation

basics

~20 s

RSA encrypts one integer smaller than the modulus, minus padding overhead - a couple of hundred bytes - and there is no chaining mode to extend it. So generate a random symmetric key, encrypt the bulk with it, and use the public key only to wrap that key.

solid answer

~50 s

The primitive operates on a single integer modulo n, so the plaintext must be numerically smaller than the modulus. A 2048-bit modulus is 256 bytes; randomized padding consumes a fixed overhead of roughly two hash lengths plus two bytes, leaving under 200 usable bytes. There is no defined mode of operation to extend a public-key primitive over a stream, and splitting the file into blocks is a homemade mode that leaks equal blocks and permits reordering. Performance seals it: the modular exponentiation is orders of magnitude slower per byte than a symmetric cipher with hardware support. Curve-based schemes cannot encrypt bulk data at all, since they agree or encapsulate a key. So: draw a fresh random data key, encrypt the payload with an authenticated symmetric cipher, wrap the data key under each recipient's public key, and ship the wrapped keys alongside the ciphertext with a key identifier.

go deeper

for a junior

Know that asymmetric crypto encrypts a small key and a symmetric cipher encrypts the data.

for a middle

Derive the limit from modulus size minus padding, and explain why there is no chaining mode.

for a senior

Cover envelope layout, per-object data keys, multi-recipient rewrap and hardware-held unwrap.

for a principal

Treat the envelope format and key identifiers as the durable contract that makes rotation, revocation and re-encryption tractable at scale.

## Deriving the ceiling The RSA operation is arithmetic on integers modulo n: the message is interpreted as a number and must be smaller than the modulus, or the result is ambiguous. The modulus size is the key size, so a 2048-bit key gives a 256-byte block and a 3072-bit key gives 384 bytes. Secure padding is not optional (an unpadded operation is deterministic and malleable), and randomized padding costs a fixed overhead of about two hash outputs plus a couple of bytes - roughly 66 bytes with a 256-bit hash - leaving under 200 usable bytes on a 2048-bit key. That is the derivation: usable payload equals modulus bytes minus padding overhead. ## Why you cannot just loop Symmetric ciphers have standardized modes that turn a fixed-width block cipher into something that safely handles arbitrary length. Public-key primitives have no such mode. Encrypting a file chunk by chunk under the same public key is an ad-hoc codebook construction: identical chunks yield identical ciphertext, chunks can be deleted, duplicated or reordered undetectably, and you have invented a scheme nobody has analysed. The cost argument is just as decisive - the modular exponentiation is several orders of magnitude slower per byte than a symmetric cipher, so the file would take minutes rather than milliseconds. ## Families diverge on what the wrap even is With RSA you literally encrypt the data key under the recipient's public key. With elliptic-curve Diffie-Hellman there is no encryption step: you generate an ephemeral key pair, agree a shared secret with the recipient's static public key, run it through a key-derivation function and use the result to wrap the data key; the ephemeral public value travels with the ciphertext. With a post-quantum key-encapsulation mechanism the primitive hands you a random shared secret plus an encapsulation blob. All three end at the same place - a symmetric key protecting the bulk - by different routes, which is why the envelope format, not the primitive, is what an implementation actually standardises. ## What the envelope buys beyond size - **Multiple recipients.** One bulk ciphertext, the data key wrapped once per recipient. Adding a recipient is a rewrap, not a re-encryption. - **Cheap rotation of the asymmetric key.** Rotating the key pair means rewrapping small data keys; the terabytes are untouched. This only works if every ciphertext records which key wrapped it - a key identifier in the envelope is what makes rotation and revocation possible at all. - **A clean split of responsibility.** The private key can live in hardware that only ever performs the small unwrap operation and never sees the payload. ## Two failure modes to name The data key must come from a cryptographically secure random source and must be fresh per object; reusing one across objects turns a single compromise into a total one. And the bulk cipher must be authenticated - the wrap protects the key, not the payload, so an attacker who cannot decrypt can still tamper with unauthenticated bulk ciphertext.

  • How does this construction let you add a new recipient to an existing encrypted object cheaply?
    The bulk ciphertext is untouched. You unwrap the data key once with an existing private key and rewrap it under the new recipient's public key, appending another small wrapped-key entry to the envelope. Cost is constant per recipient rather than proportional to payload size, which is also why removing a recipient is weaker than it looks - anyone who already read the data key keeps it.
  • If the wrapped key is protected by the public key, why does the bulk cipher still need integrity protection?
    The wrap only guarantees that nobody else can learn the data key. It says nothing about the ciphertext that key protects. Without an authenticated mode an attacker can flip or splice bytes in the payload and the recipient will decrypt corrupted or attacker-influenced plaintext without noticing. Confidentiality and integrity are separate properties and you must obtain both.

saying these in an interview costs you the question

  • Proposing to split a large payload into modulus-sized blocks and encrypt each one - a homemade codebook mode.
  • Saying the limit is about performance only, missing that the plaintext must be numerically smaller than the modulus.
  • Reusing one data key across many objects, or deriving it from something predictable rather than a secure random source.
  • Omitting a key identifier from the envelope, which makes rotation and multi-key decryption impossible.

context