SubtleCrypto
Implements
Methods
decrypt()
decrypt<Cipher>(algorithm, key, data): Promise<ArrayBuffer>
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").
Type Parameters
| Type Parameter |
|---|
Cipher extends "AES-CBC" | "AES-CTR" | "AES-XTS" |
Parameters
| Parameter | Type |
|---|---|
algorithm | EncryptionAlgorithm<Cipher> |
key | CryptoKey<Cipher> |
data | BufferSource |
Returns
A Promise which will be fulfilled with the decrypted data (also known as "plaintext") as an ArrayBuffer.
Implementation of
globalThis.SubtleCrypto.decrypt
See
https://developer.mozilla.org/docs/Web/API/SubtleCrypto/decrypt
deriveBits()
deriveBits(algorithm, baseKey, length): Promise<ArrayBuffer>
Parameters
| Parameter | Type |
|---|---|
algorithm | AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params |
baseKey | CryptoKey<never> |
length | number |
Returns
Implementation of
globalThis.SubtleCrypto.deriveBits
deriveKey()
Parameters
| Parameter | Type |
|---|---|
algorithm | AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params |
baseKey | CryptoKey<never> |
derivedKeyType | AlgorithmIdentifier | HkdfParams | Pbkdf2Params | AesDerivedKeyParams | HmacImportParams |
extractable | boolean |
keyUsages | KeyUsage[] |
Returns
Implementation of
globalThis.SubtleCrypto.deriveKey
digest()
digest(algorithm, data): Promise<ArrayBuffer>
Generates a digest of the given data. A digest is a short fixed-length value derived from some variable-length input. Cryptographic digests should exhibit collision-resistance, meaning that it's hard to come up with two different inputs that have the same digest value.
It takes as its arguments an identifier for the digest algorithm to use and the data to digest. It returns a Promise which will be fulfilled with the digest.
Note that this API does not support streaming input: you must read the entire input into memory before passing it into the digest function.
Parameters
| Parameter | Type | Description |
|---|---|---|
algorithm | AlgorithmIdentifier | This may be a string or an object with a single property name that is a string. The string names the hash function to use. Supported values are: - "SHA-1" (but don't use this in cryptographic applications) - "SHA-256" - "SHA-384" - "SHA-512" |
data | BufferSource | An ArrayBuffer, a TypedArray or a DataView object containing the data to be digested |
Returns
Implementation of
globalThis.SubtleCrypto.digest
See
https://developer.mozilla.org/docs/Web/API/SubtleCrypto/digest
encrypt()
encrypt<Cipher>(algorithm, key, data): Promise<ArrayBuffer>
Encrypts plaintext data.
It takes as its arguments a key to encrypt with, some algorithm-specific parameters, and the data to encrypt (also known as "plaintext").
Type Parameters
| Type Parameter |
|---|
Cipher extends "AES-CBC" | "AES-CTR" | "AES-XTS" |
Parameters
| Parameter | Type |
|---|---|
algorithm | EncryptionAlgorithm<Cipher> |
key | CryptoKey<Cipher> |
data | BufferSource |
Returns
A Promise which will be fulfilled with the encrypted data (also known as "ciphertext") as an ArrayBuffer.
Implementation of
globalThis.SubtleCrypto.encrypt
See
https://developer.mozilla.org/docs/Web/API/SubtleCrypto/encrypt
exportKey()
exportKey(format, key)
exportKey(format, key): Promise<JsonWebKey>
Parameters
| Parameter | Type |
|---|---|
format | "jwk" |
key | CryptoKey<never> |
Returns
Implementation of
globalThis.SubtleCrypto.exportKey
exportKey(format, key)
exportKey(format, key): Promise<ArrayBuffer>
Parameters
| Parameter | Type |
|---|---|
format | "pkcs8" | "raw" | "spki" |
key | CryptoKey<never> |
Returns
Implementation of
globalThis.SubtleCrypto.exportKey
generateKey()
generateKey(algorithm, extractable, keyUsages)
generateKey(algorithm, extractable, keyUsages): Promise<CryptoKeyPair<never>>
Parameters
| Parameter | Type |
|---|---|
algorithm | "Ed25519" |
extractable | boolean |
keyUsages | readonly ("sign" | "verify")[] |
Returns
Promise<CryptoKeyPair<never>>
Implementation of
globalThis.SubtleCrypto.generateKey
generateKey(algorithm, extractable, keyUsages)
generateKey(algorithm, extractable, keyUsages): Promise<CryptoKeyPair<never>>
Parameters
| Parameter | Type |
|---|---|
algorithm | RsaHashedKeyGenParams | EcKeyGenParams |
extractable | boolean |
keyUsages | readonly KeyUsage[] |
Returns
Promise<CryptoKeyPair<never>>
Implementation of
globalThis.SubtleCrypto.generateKey
generateKey(algorithm, extractable, keyUsages)
Parameters
| Parameter | Type |
|---|---|
algorithm | AesKeyGenParams |
extractable | boolean |
keyUsages | readonly KeyUsage[] |
Returns
Implementation of
globalThis.SubtleCrypto.generateKey
importKey()
importKey(format, keyData, algorithm, extractable, keyUsages)
Takes as input a key in an external, portable format and returns a
CryptoKey instance which can be used in the Web Crypto API.
Type Parameters
| Type Parameter |
|---|
Cipher extends "AES-CBC" | "AES-CTR" | "AES-XTS" |
Parameters
| Parameter | Type |
|---|---|
format | "jwk" |
keyData | JsonWebKey |
algorithm | Cipher | KeyImportParams<Cipher> |
extractable | boolean |
keyUsages | KeyUsage[] |
Returns
Implementation of
globalThis.SubtleCrypto.importKey
See
https://developer.mozilla.org/docs/Web/API/SubtleCrypto/importKey
importKey(format, keyData, algorithm, extractable, keyUsages)
Type Parameters
| Type Parameter |
|---|
Cipher extends "AES-CBC" | "AES-CTR" | "AES-XTS" |
Parameters
| Parameter | Type |
|---|---|
format | "pkcs8" | "raw" | "spki" |
keyData | BufferSource |
algorithm | Cipher | KeyImportParams<Cipher> |
extractable | boolean |
keyUsages | KeyUsage[] |
Returns
Implementation of
globalThis.SubtleCrypto.importKey
sign()
sign(algorithm, key, data): Promise<ArrayBuffer>
Parameters
| Parameter | Type |
|---|---|
algorithm | AlgorithmIdentifier | RsaPssParams | EcdsaParams |
key | CryptoKey<never> |
data | BufferSource |
Returns
Implementation of
globalThis.SubtleCrypto.sign
unwrapKey()
Parameters
| Parameter | Type |
|---|---|
format | KeyFormat |
wrappedKey | BufferSource |
unwrappingKey | CryptoKey<never> |
unwrapAlgorithm | AesCbcParams | AesCtrParams | AlgorithmIdentifier | RsaOaepParams | AesGcmParams |
unwrappedKeyAlgorithm | AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams |
extractable | boolean |
keyUsages | KeyUsage[] |
Returns
Implementation of
globalThis.SubtleCrypto.unwrapKey
verify()
verify(algorithm, key, signature, data): Promise<boolean>
Parameters
| Parameter | Type |
|---|---|
algorithm | AlgorithmIdentifier | RsaPssParams | EcdsaParams |
key | CryptoKey<never> |
signature | BufferSource |
data | BufferSource |
Returns
Promise<boolean>
Implementation of
globalThis.SubtleCrypto.verify
wrapKey()
wrapKey(format, key, wrappingKey, wrapAlgorithm): Promise<ArrayBuffer>
Parameters
| Parameter | Type |
|---|---|
format | KeyFormat |
key | CryptoKey<never> |
wrappingKey | CryptoKey<never> |
wrapAlgorithm | AesCbcParams | AesCtrParams | AlgorithmIdentifier | RsaOaepParams | AesGcmParams |
Returns
Implementation of
globalThis.SubtleCrypto.wrapKey