nx.js
Classes

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

ParameterType
algorithmEncryptionAlgorithm<Cipher>
keyCryptoKey<Cipher>
dataBufferSource

Returns

Promise<ArrayBuffer>

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>

MDN Reference

Parameters

ParameterType
algorithmAlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params
baseKeyCryptoKey<never>
lengthnumber

Returns

Promise<ArrayBuffer>

Implementation of

globalThis.SubtleCrypto.deriveBits


deriveKey()

deriveKey(algorithm, baseKey, derivedKeyType, extractable, keyUsages): Promise<CryptoKey<never>>

MDN Reference

Parameters

ParameterType
algorithmAlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params
baseKeyCryptoKey<never>
derivedKeyTypeAlgorithmIdentifier | HkdfParams | Pbkdf2Params | AesDerivedKeyParams | HmacImportParams
extractableboolean
keyUsagesKeyUsage[]

Returns

Promise<CryptoKey<never>>

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

ParameterTypeDescription
algorithmAlgorithmIdentifierThis 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"
dataBufferSourceAn ArrayBuffer, a TypedArray or a DataView object containing the data to be digested

Returns

Promise<ArrayBuffer>

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

ParameterType
algorithmEncryptionAlgorithm<Cipher>
keyCryptoKey<Cipher>
dataBufferSource

Returns

Promise<ArrayBuffer>

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>

MDN Reference

Parameters
ParameterType
format"jwk"
keyCryptoKey<never>
Returns

Promise<JsonWebKey>

Implementation of

globalThis.SubtleCrypto.exportKey

exportKey(format, key)

exportKey(format, key): Promise<ArrayBuffer>

MDN Reference

Parameters
ParameterType
format"pkcs8" | "raw" | "spki"
keyCryptoKey<never>
Returns

Promise<ArrayBuffer>

Implementation of

globalThis.SubtleCrypto.exportKey


generateKey()

generateKey(algorithm, extractable, keyUsages)

generateKey(algorithm, extractable, keyUsages): Promise<CryptoKeyPair<never>>

MDN Reference

Parameters
ParameterType
algorithm"Ed25519"
extractableboolean
keyUsagesreadonly ("sign" | "verify")[]
Returns

Promise<CryptoKeyPair<never>>

Implementation of

globalThis.SubtleCrypto.generateKey

generateKey(algorithm, extractable, keyUsages)

generateKey(algorithm, extractable, keyUsages): Promise<CryptoKeyPair<never>>

MDN Reference

Parameters
ParameterType
algorithmRsaHashedKeyGenParams | EcKeyGenParams
extractableboolean
keyUsagesreadonly KeyUsage[]
Returns

Promise<CryptoKeyPair<never>>

Implementation of

globalThis.SubtleCrypto.generateKey

generateKey(algorithm, extractable, keyUsages)

generateKey(algorithm, extractable, keyUsages): Promise<CryptoKey<never>>

MDN Reference

Parameters
ParameterType
algorithmAesKeyGenParams
extractableboolean
keyUsagesreadonly KeyUsage[]
Returns

Promise<CryptoKey<never>>

Implementation of

globalThis.SubtleCrypto.generateKey


importKey()

importKey(format, keyData, algorithm, extractable, keyUsages)

importKey<Cipher>(format, keyData, algorithm, extractable, keyUsages): Promise<CryptoKey<Cipher>>

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
ParameterType
format"jwk"
keyDataJsonWebKey
algorithmCipher | KeyImportParams<Cipher>
extractableboolean
keyUsagesKeyUsage[]
Returns

Promise<CryptoKey<Cipher>>

Implementation of

globalThis.SubtleCrypto.importKey

See

https://developer.mozilla.org/docs/Web/API/SubtleCrypto/importKey

importKey(format, keyData, algorithm, extractable, keyUsages)

importKey<Cipher>(format, keyData, algorithm, extractable, keyUsages): Promise<CryptoKey<Cipher>>

MDN Reference

Type Parameters
Type Parameter
Cipher extends "AES-CBC" | "AES-CTR" | "AES-XTS"
Parameters
ParameterType
format"pkcs8" | "raw" | "spki"
keyDataBufferSource
algorithmCipher | KeyImportParams<Cipher>
extractableboolean
keyUsagesKeyUsage[]
Returns

Promise<CryptoKey<Cipher>>

Implementation of

globalThis.SubtleCrypto.importKey


sign()

sign(algorithm, key, data): Promise<ArrayBuffer>

MDN Reference

Parameters

ParameterType
algorithmAlgorithmIdentifier | RsaPssParams | EcdsaParams
keyCryptoKey<never>
dataBufferSource

Returns

Promise<ArrayBuffer>

Implementation of

globalThis.SubtleCrypto.sign


unwrapKey()

unwrapKey(format, wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages): Promise<CryptoKey<never>>

MDN Reference

Parameters

ParameterType
formatKeyFormat
wrappedKeyBufferSource
unwrappingKeyCryptoKey<never>
unwrapAlgorithmAesCbcParams | AesCtrParams | AlgorithmIdentifier | RsaOaepParams | AesGcmParams
unwrappedKeyAlgorithmAlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams
extractableboolean
keyUsagesKeyUsage[]

Returns

Promise<CryptoKey<never>>

Implementation of

globalThis.SubtleCrypto.unwrapKey


verify()

verify(algorithm, key, signature, data): Promise<boolean>

MDN Reference

Parameters

ParameterType
algorithmAlgorithmIdentifier | RsaPssParams | EcdsaParams
keyCryptoKey<never>
signatureBufferSource
dataBufferSource

Returns

Promise<boolean>

Implementation of

globalThis.SubtleCrypto.verify


wrapKey()

wrapKey(format, key, wrappingKey, wrapAlgorithm): Promise<ArrayBuffer>

MDN Reference

Parameters

ParameterType
formatKeyFormat
keyCryptoKey<never>
wrappingKeyCryptoKey<never>
wrapAlgorithmAesCbcParams | AesCtrParams | AlgorithmIdentifier | RsaOaepParams | AesGcmParams

Returns

Promise<ArrayBuffer>

Implementation of

globalThis.SubtleCrypto.wrapKey

On this page