wrapKey method

Returns a KeyOperation object which will asynchronously return an array containing the key material of key, encrypted with keyEncryptionKey using the specified keyWrappingAlgorithm.




var retVal = SubtleCrypto.wrapKey(key, keyEncryptionKey, keyWrappingAlgorithm);


key [in]

Type: Key

The Key object whose key material is to be extracted.

keyEncryptionKey [in]

Type: Key

This Key object is used to encrypt the key material.

keyWrappingAlgorithm [in]

Type: any

An object identifying the cryptographic algorithm to use for encrypting the key material (along with any required algorithmic parameters). The supported cryptographic algorithms are as follows:

  • AES-KW

Return value

Type: KeyOperation

An object that will asynchronously return the encrypted key material.


The Key object received by the keyEncryptionKey parameter is used to encrypt the content master key, not the key itself (this key is encrypted using the content master key.

The wrapKey method protects key material in a JSON Web Key (JWK) structure encapsulated with JSON Web Encryption (JWE). Specifically, the key material of key is encrypted using a randomly-generated content encryption key, which in turn is encrypted with keyEncryptionKey using the specified keyWrappingAlgorithm.

The algorithm used for the content encryption key is always AES-GCM. The wrapKey method can be used to wrap the key material for any Key object.

For a code example, see unwrapKey.

See also




© 2014 Microsoft