Crypto API
chevron down
 

Crypto API

Variable: subtle

Type: SubtleCrypto

New in SDK 2.0

Interface: SubtleCrypto

New in SDK 2.0

A set of Cryptographic methods.

Methods

decrypt()

decrypt(algorithm: AlgorithmAesGcm, key: CryptoKey, data: BufferSource)

Returns: Promise<ArrayBuffer>

New in SDK 4.0

Decrypts data using specified algorithm and key.

Parameter: data The data to decrypt.

digest()

digest(algorithm: Algorithm<"SHA-256">, data: BufferSource)

Returns: Promise<ArrayBuffer>

New in SDK 2.0

Digests data using the given algorithm.

Parameter: data The data to digest.

encrypt()

encrypt(algorithm: AlgorithmAesGcm, key: CryptoKey, data: BufferSource)

Returns: Promise<ArrayBuffer>

New in SDK 4.0

Encrypts data using specified algorithm and key.

Parameter: data The data to encrypt.

exportKey()

exportKey(format: "raw", key: CryptoKey)

Returns: Promise<ArrayBuffer>

New in SDK 4.0

Export the key's data into an ArrayBuffer.

To export a key, the key must have CryptoKey.extractable set to true

Parameter: key The CryptoKey to export

importKey()

importKey(format: "raw", keyData: BufferSource, algorithm: string | KeyAlgorithm, extractable: boolean, keyUsages: string[])

Returns: Promise<CryptoKey>

New in SDK 4.0

Import a key and returns a CryptoKey object

Parameter: keyUsages An Array indicating what can be done with the key.

sign()

sign(algorithm: Algorithm<"HMAC">, key: CryptoKey, data: BufferSource)

Returns: Promise<ArrayBuffer>

New in SDK 4.0

Sign data using the given algorithm and key.

Parameter: data The data to digest.

verify()

verify(algorithm: Algorithm<"HMAC">, key: CryptoKey, signature: BufferSource, data: BufferSource)

Returns: Promise<Boolean>

New in SDK 4.0

Verify the signature of data using the given signature, key and algorithm.

Parameter: data The data to digest.

Class: CryptoKey

New in SDK 4.0

Class to handle Cryptographic key.

Properties

readonly algorithm

KeyAlgorithm

The algorithm that can be used with this key

readonly extractable

boolean

Indicates if the key can be extracted

readonly type

"secret" or "public" or "private"

The type of the key

readonly usages

CryptoKeyUsage[]

Possible Usage for this key

Interface: KeyAlgorithm

New in SDK 4.0

Algorithms supported by a key.

Properties

hash

string or undefined

Digest function in case desired algorithm is "HMAC". Eg.: "SHA-256"

name

string

Name of the desired algorithm. Eg.: "AES-GCM", "HMAC"

CryptoKeyUsage

String: "encrypt" | "decrypt" | "sign" | "verify" | "deriveKey" | "deriveBits" | "wrapKey" | "unwrapKey"

New in SDK 4.0

List of operations a key can be used for.

Interface: AlgorithmAesGcm

New in SDK 4.0

Properties

additionalData

ArrayBuffer or Int8Array or Uint8Array or Int16Array or Uint16Array or Int32Array or Uint32Array or undefined

Additional data that will not be encrypted but will be authenticated along with the encrypted data

iv

BufferSource

12-bytes initialization vector

name

"AES-GCM"

Algorithm name

tagLength

number or undefined

Size in bits of the authentication tag generated in the encryption operation and used for authentication in the corresponding decryption

Algorithm

String: T | { name: T; }

New in SDK 2.0

An encryption/decryption/digest algorithm. Can be specified as a name "SHA-256" if there are no parameters, or as an object, possibly with parameters { name: "SHA-256", foo: bar }.

getRandomValues()

New in SDK 4.0

Fill an array with cryptographically strong random values.

import { getRandomValues } from "crypto";
// get 8 random 16-bit unsigned integers
let myRandomValues = new Uint16Array(8);
getRandomValues(myRandomValues);

crypto.getRandomValues(values: TypedArray)

Parameters

values: TypedArray

Array of values that will be filled with random numbers.

BufferSource

String: ArrayBuffer | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array

TypedArray

String: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array