Skip to content
PKIjsPKIjsPKIjsv4.0.1

CryptoEngine

Default cryptographic engine for Web Cryptography API

new CryptoEngine(parameters): CryptoEngine

Constructor for CryptoEngine class

CryptoEngineParameters

CryptoEngine

AbstractCryptoEngine.constructor

crypto: Crypto

AbstractCryptoEngine.crypto


name: string

AbstractCryptoEngine.name


subtle: SubtleCrypto

AbstractCryptoEngine.subtle

convert(inputFormat, outputFormat, keyData, algorithm, extractable, keyUsages): Promise<ArrayBuffer | JsonWebKey>

Convert WebCrypto keys between different export formats

KeyFormat

KeyFormat

ArrayBuffer | JsonWebKey

Algorithm

boolean

KeyUsage[]

Promise<ArrayBuffer | JsonWebKey>


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>

AbstractCryptoEngine.decrypt


decryptEncryptedContentInfo(parameters): Promise<ArrayBuffer>

Decrypt data stored in “EncryptedContentInfo” object using parameters

CryptoEngineDecryptParams

Promise<ArrayBuffer>

AbstractCryptoEngine.decryptEncryptedContentInfo


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

Promise<ArrayBuffer>

AbstractCryptoEngine.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>

AbstractCryptoEngine.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>

AbstractCryptoEngine.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>

AbstractCryptoEngine.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>

AbstractCryptoEngine.encrypt


encryptEncryptedContentInfo(parameters): Promise<EncryptedContentInfo>

Specialized function encrypting “EncryptedContentInfo” object using parameters

CryptoEngineEncryptParams

Promise<EncryptedContentInfo>

AbstractCryptoEngine.encryptEncryptedContentInfo


exportKey(format, key): Promise<JsonWebKey>

Export WebCrypto keys to different formats

"jwk"

CryptoKey

Promise<JsonWebKey>

AbstractCryptoEngine.exportKey

exportKey(format, key): Promise<ArrayBuffer>

Export WebCrypto keys to different formats

"pkcs8" | "raw" | "spki"

CryptoKey

Promise<ArrayBuffer>

AbstractCryptoEngine.exportKey

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

Export WebCrypto keys to different formats

string

CryptoKey

Promise<ArrayBuffer | JsonWebKey>

AbstractCryptoEngine.exportKey


fillPublicKeyParameters(publicKeyInfo, signatureAlgorithm): CryptoEnginePublicKeyParams

PublicKeyInfo

AlgorithmIdentifier

CryptoEnginePublicKeyParams


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"

boolean

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

Promise<CryptoKeyPair>

AbstractCryptoEngine.generateKey

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

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

boolean

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

Promise<CryptoKeyPair>

AbstractCryptoEngine.generateKey

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

RsaHashedKeyGenParams | EcKeyGenParams

boolean

KeyUsage[]

Promise<CryptoKeyPair>

AbstractCryptoEngine.generateKey

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

AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params

boolean

KeyUsage[]

Promise<CryptoKey>

AbstractCryptoEngine.generateKey

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

AlgorithmIdentifier

boolean

KeyUsage[]

Promise<CryptoKey | CryptoKeyPair>

AbstractCryptoEngine.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

AbstractCryptoEngine.getAlgorithmByOID

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

AbstractCryptoEngine.getAlgorithmByOID


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

AbstractCryptoEngine.getAlgorithmParameters


getHashAlgorithm(signatureAlgorithm): string

Getting hash algorithm by signature algorithm

AlgorithmIdentifier

Signature algorithm

string

AbstractCryptoEngine.getHashAlgorithm


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

Get OID for each specific algorithm

Algorithm

WebCrypto Algorithm

boolean = false

If true throws exception on unknown algorithm. Default is false

string

Name of the target

string

Throws Error exception if unknown WebCrypto algorithm

AbstractCryptoEngine.getOIDByAlgorithm


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

PublicKeyInfo

AlgorithmIdentifier

CryptoEnginePublicKeyParams

Promise<CryptoKey>

AbstractCryptoEngine.getPublicKey


getRandomValues<T>(array): T

T extends ArrayBufferView<ArrayBufferLike> | null

T

T

AbstractCryptoEngine.getRandomValues


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

Get signature parameters by analyzing private key algorithm

CryptoKey

The private key user would like to use

string = "SHA-1"

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

Promise<CryptoEngineSignatureParams>

AbstractCryptoEngine.getSignatureParameters


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

KeyFormat

BufferSource | JsonWebKey

AlgorithmIdentifier

boolean

KeyUsage[]

Promise<CryptoKey>

AbstractCryptoEngine.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>

AbstractCryptoEngine.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>

AbstractCryptoEngine.signWithPrivateKey


stampDataWithPassword(parameters): Promise<ArrayBuffer>

Stamping (signing) data using algorithm similar to HMAC

CryptoEngineStampDataWithPasswordParams

Promise<ArrayBuffer>

AbstractCryptoEngine.stampDataWithPassword


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>

AbstractCryptoEngine.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>

AbstractCryptoEngine.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>

AbstractCryptoEngine.verify


verifyDataStampedWithPassword(parameters): Promise<boolean>

CryptoEngineVerifyDataStampedWithPasswordParams

Promise<boolean>

AbstractCryptoEngine.verifyDataStampedWithPassword


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>

AbstractCryptoEngine.verifyWithPublicKey


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>

AbstractCryptoEngine.wrapKey