Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Key Wrapping?

Key wrapping is encrypting one cryptographic key with another so it can be stored or transported safely. Dedicated algorithms exist because keys are not ordinary plaintext.

Illustration for the cybersecurity term Key Wrapping
Home / Blog / Cybersecurity Terms / What Is Key Wrapping?
17 November 2026

What Is Key Wrapping?

What Is Key Wrapping?

A cryptographic key has to leave the device that created it more often than people expect. It must be backed up, replicated to another region, handed to a hardware module, exported from one system and imported into another, or stored next to the data it protects. Key wrapping is the practice of encrypting that key under a second key — the key encryption key, or KEK — so that the wrapped form can be written to disk or sent over a network without exposing anything.

The wrapped key is sometimes called a blob or a cryptogram. It is useless to anyone who cannot reach the KEK, which is usually held in a hardware security module or a managed key service.

Why Keys Need Their Own Algorithms

You could wrap a key with ordinary AES-GCM, and plenty of systems do. Purpose-built wrapping algorithms exist because key material has properties that ordinary data does not:

AES-KW, specified in RFC 3394, answers all three. It is deterministic, needs no nonce, and includes a fixed integrity check value so that unwrapping either returns the exact original key or fails outright. AES-KWP in RFC 5649 extends it to inputs that are not a multiple of eight bytes. AES-GCM-SIV and AES-SIV are modern alternatives where nonce misuse resistance is wanted alongside wrapping.

The Wrapping Options in Use

MechanismKEK typeTypical use
AES-KW / AES-KWPSymmetricHSM backup, PKCS#11 C_WrapKey, JWE A256KW
RSA-OAEPAsymmetricImporting a key into a service that published a public wrapping key
ECDH-ES plus AES-KWAsymmetric to symmetricJWE key agreement, encrypting to a recipient’s public key
AES-GCMSymmetricGeneral purpose; acceptable with strict nonce handling

The asymmetric options matter for one particular workflow: bring your own key. Cloud providers publish a public wrapping key, you encrypt your own key material under it, and the result can only be unwrapped inside their HSM. The plaintext key never exists outside your premises and theirs.

Wrapping Versus Envelope Encryption

The two terms are often used interchangeably, and they are not the same thing. Key wrapping is the cryptographic operation: encrypt key A with key B. Envelope encryption is the architectural pattern that uses it: generate a data key, encrypt the data locally, wrap the data key with a master key, and store the wrapped form alongside the ciphertext.

Put another way, wrapping is the verb and envelope encryption is the design. You will also find wrapping used outside that pattern entirely — in HSM backup and replication, in PKCS#11 key transfer between modules, in TPM key hierarchies where each key is sealed to its parent, and in disk encryption, where the volume key is wrapped by each key protector in turn.

Getting It Right

  1. Bind context to the wrap. Include an authenticated context — key identifier, tenant, purpose — so a wrapped key cannot be replayed into a different slot. Cloud key services call this an encryption context or additional authenticated data, and omitting it is a common oversight.
  2. Mark keys non-exportable where they should never be wrapped. If a signing key can be wrapped out of a module, a sufficiently privileged attacker will eventually do so. HSMs let you set this attribute at creation, and it cannot be changed afterwards.
  3. Control who can call unwrap. The right to unwrap is the right to use the key. Policies that grant decrypt or unwrap broadly make the wrapping decorative.
  4. Watch for wrapping oracles. An interface that lets a caller wrap arbitrary data under a KEK, or unwrap arbitrary blobs and report what happened, can be turned into a decryption service. PKCS#11 has a long research history of exactly these attacks.
  5. Log every operation. Wrap and unwrap calls are the audit trail for key use, and anomalies there are among the earliest signals of credential compromise.
  6. Keep the KEK somewhere stronger than the key it protects. Wrapping a key with another key stored in the same configuration file achieves nothing beyond an extra step.

That last point is the failure we see most often: a correctly implemented wrapping scheme whose KEK sits in an environment variable next to the wrapped blob. The cryptography is fine; the hierarchy is a circle. Key hierarchies and the policies around them are part of what we assess in our cloud security services.

FAQ – Frequently Asked Questions

Why Not Just Encrypt a Key with AES-GCM?

You can, and many systems do successfully. Dedicated wrapping algorithms such as AES-KW remove the need to manage a unique nonce for every wrap and build in an integrity check designed for key-sized inputs. Where your platform handles nonces reliably, AES-GCM with an authenticated context is a perfectly sound choice.

What Is a Key Encryption Key?

A key whose only job is to protect other keys, never application data. It sits higher in the hierarchy, usually inside an HSM or a key management service, and ideally is non-exportable. Separating it from data encryption keys limits exposure, enables rotation without re-encrypting data, and gives you a single auditable control point.

Can I Import My Own Key into a Cloud KMS?

Yes, through bring your own key. The provider publishes a public wrapping key, you encrypt your key material with RSA-OAEP, and only their HSM can unwrap it. This keeps key generation under your control and can satisfy regulatory requirements, at the cost of owning the backup and recovery of that material yourself.

Is a Wrapped Key Safe to Store in a Database?

Yes, provided the key encryption key is held somewhere genuinely separate with its own access control. That is exactly the design behind envelope encryption. It stops being safe when the KEK lives in the same application configuration, container image, or repository as the wrapped blob, which removes the separation the scheme depends on.

Related Terms

You May Be Interested In These

What Is the NIS2 Directive?

Cybersecurity Terms

17 November 2026

What Is the NIS2 Directive?

Read More
What Is Kubernetes RBAC Privilege Escalation?

Cybersecurity Terms

17 November 2026

What Is Kubernetes RBAC Privilege Escalation?

Read More