unwrapKey method

JSPromise<CryptoKey> unwrapKey(
  1. KeyFormat format,
  2. BufferSource wrappedKey,
  3. CryptoKey unwrappingKey,
  4. AlgorithmIdentifier unwrapAlgorithm,
  5. AlgorithmIdentifier unwrappedKeyAlgorithm,
  6. bool extractable,
  7. JSArray<JSString> keyUsages,
)

The unwrapKey() method of the SubtleCrypto interface "unwraps" a key. This means that it takes as its input a key that has been exported and then encrypted (also called "wrapped"). It decrypts the key and then imports it, returning a CryptoKey object that can be used in the Web Crypto API.

As with SubtleCrypto.importKey(), you specify the key's import format and other attributes of the key to import details such as whether it is extractable, and which operations it can be used for.

But because unwrapKey() also decrypts the key to be imported, you also need to pass in the key that must be used to decrypt it. This is sometimes called the "unwrapping key".

The inverse of unwrapKey() is SubtleCrypto.wrapKey: while unwrapKey is composed of decrypt + import, wrapKey is composed of encrypt + export.

Implementation

external JSPromise<CryptoKey> unwrapKey(
  KeyFormat format,
  BufferSource wrappedKey,
  CryptoKey unwrappingKey,
  AlgorithmIdentifier unwrapAlgorithm,
  AlgorithmIdentifier unwrappedKeyAlgorithm,
  bool extractable,
  JSArray<JSString> keyUsages,
);