wrapKey method
- KeyFormat format,
- CryptoKey key,
- CryptoKey wrappingKey,
- AlgorithmIdentifier wrapAlgorithm,
The wrapKey()
method of the SubtleCrypto interface "wraps" a key.
This means that it exports the key in an external, portable format, then
encrypts the exported key.
Wrapping a key helps protect it in untrusted environments, such as inside
an otherwise unprotected data store or in transmission over an unprotected
network.
As with SubtleCrypto.exportKey, you specify an
export format
for the key.
To export a key, it must have CryptoKey.extractable set to true
.
But because wrapKey()
also encrypts the key to be exported, you also
need to pass in the key that must be used to encrypt it.
This is sometimes called the "wrapping key".
The inverse of wrapKey()
is SubtleCrypto.unwrapKey: while wrapKey
is
composed of export + encrypt, unwrapKey
is composed of import + decrypt.
Implementation
external JSPromise<JSAny?> wrapKey(
KeyFormat format,
CryptoKey key,
CryptoKey wrappingKey,
AlgorithmIdentifier wrapAlgorithm,
);