Skip to content
PKIjsPKIjsPKIjsv4.0.1

ICryptoEngine

  • SubtleCrypto

crypto: Crypto


name: string


subtle: SubtleCrypto

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

The decrypt() method of the SubtleCrypto interface 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”). It returns a Promise which will be fulfilled with the decrypted data (also known as “plaintext”).

MDN Reference

AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams

CryptoKey

BufferSource

Promise<ArrayBuffer>

SubtleCrypto.decrypt


decryptEncryptedContentInfo(parameters): Promise<ArrayBuffer>

Decrypt data stored in “EncryptedContentInfo” object using parameters

CryptoEngineDecryptParams

Promise<ArrayBuffer>


deriveBits(algorithm, baseKey, length?): Promise<ArrayBuffer>

The deriveBits() method of the SubtleCrypto interface can be used to derive an array of bits from a base key.

MDN Reference

AlgorithmIdentifier | Pbkdf2Params | EcdhKeyDeriveParams | HkdfParams

CryptoKey

number | null

Promise<ArrayBuffer>

SubtleCrypto.deriveBits


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

The deriveKey() method of the SubtleCrypto interface can be used to derive a secret key from a master key.

MDN Reference

AlgorithmIdentifier | Pbkdf2Params | EcdhKeyDeriveParams | HkdfParams

CryptoKey

AlgorithmIdentifier | Pbkdf2Params | HkdfParams | AesDerivedKeyParams | HmacImportParams

boolean

KeyUsage[]

Promise<CryptoKey>

SubtleCrypto.deriveKey

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

The deriveKey() method of the SubtleCrypto interface can be used to derive a secret key from a master key.

MDN Reference

AlgorithmIdentifier | Pbkdf2Params | EcdhKeyDeriveParams | HkdfParams

CryptoKey

AlgorithmIdentifier | Pbkdf2Params | HkdfParams | AesDerivedKeyParams | HmacImportParams

boolean

Iterable<KeyUsage>

Promise<CryptoKey>

SubtleCrypto.deriveKey


digest(algorithm, data): Promise<ArrayBuffer>

The digest() method of the SubtleCrypto interface generates a digest of the given data, using the specified hash function. 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.

MDN Reference

AlgorithmIdentifier

BufferSource

Promise<ArrayBuffer>

SubtleCrypto.digest


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

The encrypt() method of the SubtleCrypto interface encrypts data.

MDN Reference

AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams

CryptoKey

BufferSource

Promise<ArrayBuffer>

SubtleCrypto.encrypt


encryptEncryptedContentInfo(parameters): Promise<EncryptedContentInfo>

Specialized function encrypting “EncryptedContentInfo” object using parameters

CryptoEngineEncryptParams

Promise<EncryptedContentInfo>


exportKey(format, key): Promise<JsonWebKey>

The exportKey() method of the SubtleCrypto interface exports a key: that is, it takes as input a CryptoKey object and gives you the key in an external, portable format.

MDN Reference

"jwk"

CryptoKey

Promise<JsonWebKey>

SubtleCrypto.exportKey

exportKey(format, key): Promise<ArrayBuffer>

"pkcs8" | "raw" | "spki"

CryptoKey

Promise<ArrayBuffer>

SubtleCrypto.exportKey

exportKey(format, key): Promise<ArrayBuffer | JsonWebKey>

KeyFormat

CryptoKey

Promise<ArrayBuffer | JsonWebKey>

SubtleCrypto.exportKey


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

The generateKey() method of the SubtleCrypto interface is used to generate a new key (for symmetric algorithms) or key pair (for public-key algorithms).

MDN Reference

"Ed25519" | { name: "Ed25519"; }

boolean

readonly ("sign" | "verify")[]

Promise<CryptoKeyPair>

SubtleCrypto.generateKey

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

"X25519" | { name: "X25519"; }

boolean

readonly ("deriveBits" | "deriveKey")[]

Promise<CryptoKeyPair>

SubtleCrypto.generateKey

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

RsaHashedKeyGenParams | EcKeyGenParams

boolean

readonly KeyUsage[]

Promise<CryptoKeyPair>

SubtleCrypto.generateKey

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

AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params

boolean

readonly KeyUsage[]

Promise<CryptoKey>

SubtleCrypto.generateKey

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

AlgorithmIdentifier

boolean

KeyUsage[]

Promise<CryptoKey | CryptoKeyPair>

SubtleCrypto.generateKey

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

The generateKey() method of the SubtleCrypto interface is used to generate a new key (for symmetric algorithms) or key pair (for public-key algorithms).

MDN Reference

"Ed25519" | { name: "Ed25519"; }

boolean

readonly ("sign" | "verify")[]

Promise<CryptoKeyPair>

SubtleCrypto.generateKey

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

"X25519" | { name: "X25519"; }

boolean

readonly ("deriveBits" | "deriveKey")[]

Promise<CryptoKeyPair>

SubtleCrypto.generateKey

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

RsaHashedKeyGenParams | EcKeyGenParams

boolean

readonly KeyUsage[]

Promise<CryptoKeyPair>

SubtleCrypto.generateKey

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

AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params

boolean

readonly KeyUsage[]

Promise<CryptoKey>

SubtleCrypto.generateKey

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

AlgorithmIdentifier

boolean

Iterable<KeyUsage>

Promise<CryptoKey | CryptoKeyPair>

SubtleCrypto.generateKey


getAlgorithmByOID<T>(oid, safety?, target?): object | T

Gets WebCrypto algorithm by wel-known OID

T extends Algorithm = Algorithm

string

algorithm identifier

boolean

if true throws exception on unknown algorithm identifier

string

name of the target

object | T

Returns WebCrypto algorithm or an empty object

getAlgorithmByOID<T>(oid, safety, target?): T

Gets WebCrypto algorithm by wel-known OID

T extends Algorithm = Algorithm

string

algorithm identifier

true

if true throws exception on unknown algorithm identifier

string

name of the target

T

Returns WebCrypto algorithm

Throws Error exception if unknown algorithm identifier


getAlgorithmParameters(algorithmName, operation): CryptoEngineAlgorithmParams

Get default algorithm parameters for each kind of operation

string

Algorithm name to get common parameters for

CryptoEngineAlgorithmOperation

Kind of operation: “sign”, “encrypt”, “generateKey”, “importKey”, “exportKey”, “verify”

CryptoEngineAlgorithmParams


getHashAlgorithm(signatureAlgorithm): string

Getting hash algorithm by signature algorithm

AlgorithmIdentifier

Signature algorithm

string


getOIDByAlgorithm(algorithm, safety?, target?): string

Get OID for each specific algorithm

Algorithm

WebCrypto Algorithm

boolean

If true throws exception on unknown algorithm. Default is false

string

Name of the target

string

Throws Error exception if unknown WebCrypto algorithm


getPublicKey(publicKeyInfo, signatureAlgorithm, parameters?): Promise<CryptoKey>

PublicKeyInfo

AlgorithmIdentifier

CryptoEnginePublicKeyParams

Promise<CryptoKey>


getRandomValues<T>(array): T

T extends ArrayBufferView<ArrayBufferLike> | null

T

T


getSignatureParameters(privateKey, hashAlgorithm?): Promise<CryptoEngineSignatureParams>

Get signature parameters by analyzing private key algorithm

CryptoKey

The private key user would like to use

string

Hash algorithm user would like to use. Default is SHA-1

Promise<CryptoEngineSignatureParams>


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

The importKey() method of the SubtleCrypto interface imports a key: that is, it takes as input a key in an external, portable format and gives you a CryptoKey object that you can use in the Web Crypto API.

MDN Reference

"jwk"

JsonWebKey

AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm

boolean

readonly KeyUsage[]

Promise<CryptoKey>

SubtleCrypto.importKey

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

"pkcs8" | "raw" | "spki"

BufferSource

AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm

boolean

KeyUsage[]

Promise<CryptoKey>

SubtleCrypto.importKey

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

The importKey() method of the SubtleCrypto interface imports a key: that is, it takes as input a key in an external, portable format and gives you a CryptoKey object that you can use in the Web Crypto API.

MDN Reference

"jwk"

JsonWebKey

AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm

boolean

readonly KeyUsage[]

Promise<CryptoKey>

SubtleCrypto.importKey

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

"pkcs8" | "raw" | "spki"

BufferSource

AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm

boolean

Iterable<KeyUsage>

Promise<CryptoKey>

SubtleCrypto.importKey


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

The sign() method of the SubtleCrypto interface generates a digital signature.

MDN Reference

AlgorithmIdentifier | RsaPssParams | EcdsaParams

CryptoKey

BufferSource

Promise<ArrayBuffer>

SubtleCrypto.sign


signWithPrivateKey(data, privateKey, parameters): Promise<ArrayBuffer>

Sign data with pre-defined private key

BufferSource

Data to be signed

CryptoKey

Private key to use

CryptoEngineSignWithPrivateKeyParams

Parameters for used algorithm

Promise<ArrayBuffer>


stampDataWithPassword(parameters): Promise<ArrayBuffer>

Stamping (signing) data using algorithm similar to HMAC

CryptoEngineStampDataWithPasswordParams

Promise<ArrayBuffer>


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

The unwrapKey() method of the SubtleCrypto interface “unwraps” a key. This means that it takes as its input a key that has been exported and then encrypted (also called “wrapped”). It decrypts the key and then imports it, returning a CryptoKey object that can be used in the Web Crypto API.

MDN Reference

KeyFormat

BufferSource

CryptoKey

AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams

AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm

boolean

KeyUsage[]

Promise<CryptoKey>

SubtleCrypto.unwrapKey

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

The unwrapKey() method of the SubtleCrypto interface “unwraps” a key. This means that it takes as its input a key that has been exported and then encrypted (also called “wrapped”). It decrypts the key and then imports it, returning a CryptoKey object that can be used in the Web Crypto API.

MDN Reference

KeyFormat

BufferSource

CryptoKey

AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams

AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams | EcKeyImportParams | AesKeyAlgorithm

boolean

Iterable<KeyUsage>

Promise<CryptoKey>

SubtleCrypto.unwrapKey


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

The verify() method of the SubtleCrypto interface verifies a digital signature.

MDN Reference

AlgorithmIdentifier | RsaPssParams | EcdsaParams

CryptoKey

BufferSource

BufferSource

Promise<boolean>

SubtleCrypto.verify


verifyDataStampedWithPassword(parameters): Promise<boolean>

CryptoEngineVerifyDataStampedWithPasswordParams

Promise<boolean>


verifyWithPublicKey(data, signature, publicKeyInfo, signatureAlgorithm, shaAlgorithm?): Promise<boolean>

Verify data with the public key

BufferSource

Data to be verified

BitString | OctetString

Signature value

PublicKeyInfo

Public key information

AlgorithmIdentifier

Signature algorithm

string

Hash algorithm

Promise<boolean>


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

The wrapKey() method of the SubtleCrypto interface “wraps” a key. This means that it exports the key in an external, portable format, then encrypts the exported key. Wrapping a key helps protect it in untrusted environments, such as inside an otherwise unprotected data store or in transmission over an unprotected network.

MDN Reference

KeyFormat

CryptoKey

CryptoKey

AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams

Promise<ArrayBuffer>

SubtleCrypto.wrapKey