Crypto API
Variable: subtle
Type: SubtleCrypto
New in SDK 4.0
Interface: SubtleCrypto
New in SDK 4.0
A set of Cryptographic methods.
Methods
decrypt()
decrypt(algorithm: "AES-GCM", key: CryptoKey, data: ArrayBuffer | ArrayBufferView)
Returns: Promise<ArrayBuffer>
Decrypts data using the given algorithm and key.
Parameter: data
The data to decrypt.
digest()
digest(algorithm: "SHA-256", data: ArrayBuffer | ArrayBufferView)
Returns: Promise<ArrayBuffer>
Digests data using the given algorithm.
Parameter: data
The data to digest.
encrypt()
encrypt(algorithm: "AES-GCM", key: CryptoKey, data: ArrayBuffer | ArrayBufferView)
Returns: Promise<ArrayBuffer>
Encrypts data using the given algorithm and key.
Parameter: data
The data to decrypt.
exportKey()
exportKey(format: "raw", key: CryptoKey)
Returns: Promise<ArrayBuffer or ArrayBufferView>
Export a key and returns a key in a buffer
Parameter: key
The CryptoKey to export
generateKey()
generateKey(algorithm: string | KeyAlgorithm, extractable: boolean, keyUsages: string[])
Returns: Promise<CryptoKey or CryptoKeyPair>
Generate a key and returns a CryptoKey object
Parameter: keyUsages
An Array indicating what can be done with the key.
importKey()
importKey(format: "raw", keyData: ArrayBuffer | ArrayBufferView, algorithm: string | KeyAlgorithm, extractable: boolean, keyUsages: string[])
Returns: Promise<CryptoKey>
Import a key and returns a CryptoKey object
Parameter: keyUsages
An Array indicating what can be done with the key.
sign()
sign(algorithm: "HMAC", key: CryptoKey, data: ArrayBuffer | ArrayBufferView)
Returns: Promise<ArrayBuffer>
Sign data using the given algorithm and key.
Parameter: data
The data to digest.
verify()
verify(algorithm: "HMAC", key: CryptoKey, signature: ArrayBuffer | ArrayBufferView, data: ArrayBuffer | ArrayBufferView)
Returns: Promise<ArrayBuffer>
Verify the signature of data using the given signature, key and algorithm.
Parameter: data
The data to digest.
Class: CryptoKeyPair
New in SDK 4.0
Class to handle Cryptographic keypair.
Properties
privateKey
The private component of the keypair
publicKey
The public component of the keypair
Class: CryptoKey
New in SDK 4.0
Class to handle Cryptographic key.
Properties
readonly algorithm
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
name
string
CryptoKeyUsage
String: "encrypt" | "decrypt" | "sign" | "verify" | "deriveKey" | "deriveBits" | "wrapKey" | "unwrapKey"
New in SDK 4.0
List of operations a key can be used for.
getRandomValues()
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.
TypedArray
String: Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array
The types of supported arrays.