W3cubDocs

/DOM

SubtleCrypto.wrapKey

The SubtleCrypto.wrapKey() method returns a Promise of a wrapped symmetric key for usage (transfer, storage) in unsecure environments. The wrapped buffer returned is in the format given in parameters, and contains the key wrapped by the given wrapping key with the given algorithm.

Syntax

var result = crypto.subtle.wrapKey(format, key, wrappingKey, wrapAlgo);

Parameters

  • format is an enumerated value describing the data format in which the key must be wrapped. It can be one of the following:
  • key is the CryptoKey to wrap.
  • wrappingkey is the CryptoKey used to perform the wrapping.
  • wrapAlgo is the DOMString} representing the algorithm used to perform the wrapping. It is one of the following: AES-CBC, AES-CTR, AES-GCM, RSA-OAEP, and AES-KW.

Return value

  • result is a Promise that returns the wrapped key in the requested format.

Exceptions

The promise is rejected when one of the following exceptions is encountered:

  • InvalidAccessError when the wrapping key is not a key for the requested wrap algorithm.
  • NotSupported when trying to use an algorithm that is either unknown or isn't suitable for encryption or wrapping.
  • TypeError when trying to use an invalid format.

Specifications

Specification Status Comment
Web Cryptography API
The definition of 'SubtleCrypto.wrapKey()' in that specification.
Recommendation Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns KeyOperation instead of Promise
24 7
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/wrapKey