The interface name includes the term “subtle” to indicate that many of its algorithms have subtle usage requirements, and hence that it must be used carefully in order to provide suitable security guarantees.
Properties
decrypt()
decrypt: (algorithm, key, data) => Promise<ArrayBuffer>
The decrypt() method of the SubtleCrypto interface decrypts some encrypted
data. It takes as arguments a key to decrypt with, some optional extra
parameters, and the data to decrypt (also known as “ciphertext”). It
returns a Promise which will be fulfilled with the decrypted data (also
known as “plaintext”).
Parameters
algorithm
EncryptionAlgorithm
An object specifying the algorithm to be used,
and any extra parameters as required. The values given for the extra parameters must match
those passed into the corresponding encrypt call.
- To use RSA-OAEP, pass an RsaOaepParams object.
- To use AES-CTR, pass an AesCtrParams object.
- To use AES-CBC, pass an AesCbcParams object.
- To use AES-GCM, pass an AesGcmParams object.
key
CryptoKey
A CryptoKey containing the key to be used for decryption.
If using RSA-OAEP, this is the privateKey property of the CryptoKeyPair object.
data
BufferSource
An ArrayBuffer, a TypedArray, or a DataView
containing the data to be decrypted (also known as ciphertext).
Returns
Promise<ArrayBuffer>
A Promise that fulfills with an ArrayBuffer containing the plaintext.
Throws
InvalidArgumentError If the algorithm parameters are invalid or missing required fieldsThrows
NotSupportedError If the algorithm is not supported or parameters have unsupported valuesderiveBits()
deriveBits: (algorithm, baseKey, length) => Promise<ArrayBuffer>
The deriveBits() method of the SubtleCrypto interface can be used to derive
an array of bits from a base key.
It takes as its arguments the base key, the derivation algorithm to use, and
the length of the bits to derive. It returns a Promise which will be fulfilled
with an ArrayBuffer containing the derived bits.
Parameters
algorithm
DerivationAlgorithm
An object defining the derivation algorithm to use.
- To use ECDH, pass an EcdhKeyDeriveParams object, specifying the string
"ECDH"as thenameproperty. - To use HKDF, pass an HkdfParams object.
- To use PBKDF2, pass a Pbkdf2Params object.
baseKey
CryptoKey
A CryptoKey representing the input to
the derivation algorithm. If algorithm is ECDH, this will be the ECDH private
key. Otherwise it will be the initial key material for the derivation function:
for example, for PBKDF2 it might be a password, imported as a CryptoKey
using SubtleCrypto.importKey.
length
number
A number representing the number of bits to derive.
This number should be a multiple of 8.
Returns
Promise<ArrayBuffer>
A Promise that fulfills with an ArrayBuffer containing the derived bits.

