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 contained the key wrapped by the give wrapping key with the given algorithm.
Syntax
var result = crypto.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:"raw"
, the key as an array of bytes, usually a secret key."pkcs8"
a private key, in the IETF Public Key-Cryptographic Standard Encryption #8."spki"
, usually a public key, in the Simple public key infrastructure standard"jwk"
, the key in the JSON Web Key format.
key
is theCryptoKey
to wrap.wrappingkey
is theCryptoKey
used to perform the wrapping.wrapAlgo
is theDOMString
} representing the algorithm used to perform the wrapping. It is one of the following:AES-CBC
,AES-CTR
,AES-GCM
,RSA-OAEP
, andAES-KW
.
Return value
result
is aPromise
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. |
Candidate Recommendation | Initial definition. |
Browser compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 37 | (Yes) | 34 (34) | No support | ? | No support |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | (Yes) | 37 | (Yes) | 34.0 (34) | No support | ? | No support |
See also
Crypto
andCrypto.subtle
.SubtleCrypto
, the interface it belongs to.