Class “SubtleCrypto”
Provides a subset of the cryptographic functions in the SubtleCrypto W3C standard.
Type: | SubtleCrypto extends Object |
Constructor: | private |
Singleton: | No |
Namespace: | global |
Direct subclasses: | None |
JSX Support: | No |
Methods
decrypt(algorithm, key, data)
Decrypts the given raw data. Currently only supports the AES-GCM algorithm.
Parameter | Type | Description |
---|---|---|
algorithm | { |
|
key | CryptoKey |
|
data | ArrayBuffer | TypedArray |
Returns: Promise<ArrayBuffer>
deriveBits(algorithm, baseKey, length)
Takes a base key and derives an array of bits from it using the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
Parameter | Type | Description |
---|---|---|
algorithm | { |
|
baseKey | CryptoKey |
|
length | number |
Returns: Promise<ArrayBuffer>
deriveBits(algorithm, baseKey, length)
Takes a base key and derives an array of bits from it using the HKDF algorithm.
Parameter | Type | Description |
---|---|---|
algorithm | { |
|
baseKey | CryptoKey |
|
length | number |
Returns: Promise<ArrayBuffer>
deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages)
Takes a base key and derives a secret key from it using the Elliptic Curve Diffie-Hellman (ECDH) algorithm.
Parameter | Type | Description |
---|---|---|
algorithm | { |
|
baseKey | CryptoKey |
|
derivedKeyAlgorithm | {name: 'AES-GCM', length: number} |
|
extractable | boolean |
|
keyUsages | string[] |
deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages)
Takes a base key and derives a secret key from it using the HKDF algorithm.
Parameter | Type | Description |
---|---|---|
algorithm | { |
|
baseKey | CryptoKey |
|
derivedKeyAlgorithm | {name: 'AES-GCM', length: number} |
|
extractable | boolean |
|
keyUsages | string[] |
digest(algorithm, data)
Provides the digest value of the given data as an ArrayBuffer. Fo this the method uses the hashing algorithms provided by the operating system.
Parameter | Type | Description |
---|---|---|
algorithm | 'SHA-1' |
A string defining the hash function to use. |
data | TypedArray | ArrayBuffer |
The data to be digested. |
Returns: Promise<ArrayBuffer>
encrypt(algorithm, key, data)
Encrypts the given raw data. Currently only supports the AES-GCM algorithm.
Parameter | Type | Description |
---|---|---|
algorithm | { |
|
key | CryptoKey |
|
data | ArrayBuffer | TypedArray |
Returns: Promise<ArrayBuffer>
exportKey(format, key)
Converts a CryptoKey instances into a portable format. To export a key, the key must have extractable set to true. Supports the spki format or raw bytes.
Parameter | Type | Description |
---|---|---|
format | 'raw' | 'spki' |
|
key | CryptoKey |
Returns: Promise<ArrayBuffer>
generateKey(algorithm, extractable, keyUsages)
Generates new keys. Currently only supports the Elliptic Curve Diffie-Hellman (ECDH) algorithm to generate key pairs.
Parameter | Type | Description |
---|---|---|
algorithm | {name: 'ECDH', namedCurve: 'P-256'} |
|
extractable | boolean |
|
keyUsages | string[] |
Returns: Promise<{privateKey: CryptoKey, publicKey: CryptoKey}>
importKey(format, keyData, algorithm, extractable, keyUsages)
Takes an external key in a portable format and returns a CryptoKey object that can be used with the SubtleCrypto API. Keys may be in spki or pkcs8 format.
Parameter | Type | Description |
---|---|---|
format | 'spki' |
|
keyData | ArrayBuffer | TypedArray |
|
algorithm | {name: 'ECDH', namedCurve: 'P-256'} |
|
extractable | boolean |
|
keyUsages | string[] |