← All use cases
Key Management·18 min

Key wrapping and key exchange: moving keys without ever exposing them

Envelope encryption covers wrapping a key with your own KMS. This is about the broader problem: getting a key from one system, person, or organization to another — without it ever existing in the clear outside a trust boundary.

Developer / EngineerSecurity ArchitectIT Ops / DevOps

Three different problems, three different tools

"Get a key from A to B safely" sounds like one problem, but production systems actually face three distinct versions of it, and reaching for the wrong tool is a common real-world mistake. Wrapping a key with a symmetric KEK you already share with the recipient is one tool. Transporting a key to someone you've never shared a secret with, using their public key, is a different tool. Agreeing on a fresh shared secret with someone, without ever transmitting a key at all, is a third tool entirely — and it's the Diffie-Hellman idea from earlier in this catalog, applied at the systems level.

Symmetric key wrap (AES Key Wrap)

  • •Requires a KEK both sides already share
  • •Fast, deterministic, no IV or nonce management needed
  • •Best when moving a key between systems already inside the same trust domain

Asymmetric key transport (RSA-OAEP)

  • •No pre-shared secret needed — only the recipient's public key
  • •Ciphertext size is fixed by the modulus, regardless of key size
  • •Best when sending a key to a party you've never securely communicated with before

AES Key Wrap: a construction built specifically for keys

RFC 3394's AES Key Wrap (AES-KW) is deliberately not "just AES-GCM applied to a key" — it's a dedicated construction built around the fact that key material is already high-entropy, fixed in size, and never reused as wrapping input the way ordinary plaintext might be reused. AES-KW runs the key through six rounds of an AES-based transformation together with a fixed 64-bit integrity-check value (0xA6A6A6A6A6A6A6A6), so unwrapping with the wrong KEK fails loudly and immediately rather than silently returning garbage.

The practical result: AES-KW adds exactly 8 bytes of overhead to whatever it wraps, no matter the key size, and needs no IV or nonce at all — one of the few symmetric constructions in this catalog that's fully deterministic by design, because the input (a key) is guaranteed to already be unpredictable.

wrapped size (bytes)=key size (bytes)+8\text{wrapped size (bytes)} = \text{key size (bytes)} + 8

Practice

A system wraps a 256-bit (32-byte) AES key using AES Key Wrap (RFC 3394). How many bytes is the wrapped output?

Cross-boundary key import: wrapping as the actual API contract

"Import Key Material" flows — used when bringing an existing key into a cloud KMS, or moving one between KMS providers — are RSA-OAEP key transport in production, not a diagram: the destination KMS publishes a temporary public key and a short-lived import token, the source system wraps the key material with that public key, uploads it, and the destination KMS is the only thing able to unwrap it, using the private half it never exposed. This is exactly the asymmetric transport pattern above, just with the KMS itself as the recipient.

Key exchange: when neither side wants to transmit a key at all

Both wrapping approaches above still transmit an encrypted key. Diffie-Hellman and ECDH (covered in depth earlier in this catalog) solve a genuinely different problem: two systems derive the identical shared secret independently, without either one ever sending a key — encrypted or otherwise — across the wire. This is the pattern behind TLS's ephemeral key exchange and modern VPN tunnels, and it's the right tool whenever forward secrecy matters: if an attacker records the exchange and later compromises a long-term key, a wrapped key transported over RSA is retroactively exposed, but an ephemeral ECDH exchange leaves nothing recorded that reconstructs the session key.

The trade-off is payload size versus what you get for it. An X25519 ephemeral public key (the ECDH exchange itself) is a fixed 32 bytes, no matter what security level is needed at that curve — while an RSA-wrapped key transport payload scales with the RSA modulus, which has to be far larger than 32 bytes to reach equivalent security (the key-sizes module covers exactly why).

Practice

An X25519 ephemeral public key (used in ECDH key exchange) is 32 bytes. An RSA-2048 key-transport ciphertext is 256 bytes. How many times larger is the RSA-wrapped payload?

Choosing the right pattern

In practice these three tools compose rather than compete: a TLS session uses ECDHE to agree on a session key live, a backup system uses AES Key Wrap to move a key between two services that already trust each other, and a one-time cross-organization key handoff uses RSA-OAEP transport because there's no pre-shared secret and no live session to negotiate over.

Which tool, for which job

Already share a KEK

AES Key Wrap — fast, deterministic, minimal overhead.

No shared secret, one-off transfer

RSA-OAEP key transport — needs only the recipient's public key.

Live session, forward secrecy matters

ECDH/ECDHE key exchange — no key ever transmitted, encrypted or otherwise.

Knowledge check

Test what you just learned →

10 quick questions, with an explanation for every answer.

Up next

Running a PKI: how a certificate authority actually operates →

The X.509 module covers what's inside one certificate and how a chain verifies. This is the other half: how an organization actually runs the CA hierarchy that issues, automates, and eventually retires millions of them.