Skip to main content

CryptoEngine

Default cryptographic engine for Web Cryptography API

Extends

Constructors

new CryptoEngine()

new CryptoEngine(parameters): CryptoEngine

Constructor for CryptoEngine class

Parameters

parameters

CryptoEngineParameters

Returns

CryptoEngine

Inherited from

AbstractCryptoEngine.constructor

Properties

crypto

crypto: Crypto

Inherited from

AbstractCryptoEngine.crypto


name

name: string

Inherited from

AbstractCryptoEngine.name


subtle

subtle: SubtleCrypto

Inherited from

AbstractCryptoEngine.subtle

Methods

convert()

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

Convert WebCrypto keys between different export formats

Parameters

inputFormat

KeyFormat

outputFormat

KeyFormat

keyData

ArrayBuffer | JsonWebKey

algorithm

Algorithm

extractable

boolean

keyUsages

KeyUsage[]

Returns

Promise<ArrayBuffer | JsonWebKey>


decrypt()

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

MDN Reference

Parameters

algorithm

AesCbcParams | AesCtrParams | AesGcmParams | AlgorithmIdentifier | RsaOaepParams

key

CryptoKey

data

BufferSource

Returns

Promise<ArrayBuffer>

Inherited from

AbstractCryptoEngine.decrypt


decryptEncryptedContentInfo()

decryptEncryptedContentInfo(parameters): Promise<ArrayBuffer>

Decrypt data stored in "EncryptedContentInfo" object using parameters

Parameters

parameters

CryptoEngineDecryptParams

Returns

Promise<ArrayBuffer>

Overrides

AbstractCryptoEngine.decryptEncryptedContentInfo


deriveBits()

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

MDN Reference

Parameters

algorithm

EcdhKeyDeriveParams | AlgorithmIdentifier | HkdfParams | Pbkdf2Params

baseKey

CryptoKey

length

number

Returns

Promise<ArrayBuffer>

Inherited from

AbstractCryptoEngine.deriveBits


deriveKey()

Call Signature

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

MDN Reference

Parameters
algorithm

EcdhKeyDeriveParams | AlgorithmIdentifier | HkdfParams | Pbkdf2Params

baseKey

CryptoKey

derivedKeyType

AesDerivedKeyParams | AlgorithmIdentifier | HkdfParams | HmacImportParams | Pbkdf2Params

extractable

boolean

keyUsages

KeyUsage[]

Returns

Promise<CryptoKey>

Inherited from

AbstractCryptoEngine.deriveKey

Call Signature

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

MDN Reference

Parameters
algorithm

EcdhKeyDeriveParams | AlgorithmIdentifier | HkdfParams | Pbkdf2Params

baseKey

CryptoKey

derivedKeyType

AesDerivedKeyParams | AlgorithmIdentifier | HkdfParams | HmacImportParams | Pbkdf2Params

extractable

boolean

keyUsages

Iterable<KeyUsage>

Returns

Promise<CryptoKey>

Inherited from

AbstractCryptoEngine.deriveKey


digest()

digest(algorithm, data): Promise<ArrayBuffer>

MDN Reference

Parameters

algorithm

AlgorithmIdentifier

data

BufferSource

Returns

Promise<ArrayBuffer>

Inherited from

AbstractCryptoEngine.digest


encrypt()

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

MDN Reference

Parameters

algorithm

AesCbcParams | AesCtrParams | AesGcmParams | AlgorithmIdentifier | RsaOaepParams

key

CryptoKey

data

BufferSource

Returns

Promise<ArrayBuffer>

Inherited from

AbstractCryptoEngine.encrypt


encryptEncryptedContentInfo()

encryptEncryptedContentInfo(parameters): Promise<EncryptedContentInfo>

Specialized function encrypting "EncryptedContentInfo" object using parameters

Parameters

parameters

CryptoEngineEncryptParams

Returns

Promise<EncryptedContentInfo>

Overrides

AbstractCryptoEngine.encryptEncryptedContentInfo


exportKey()

Call Signature

exportKey(format, key): Promise<JsonWebKey>

Export WebCrypto keys to different formats

Parameters
format

"jwk"

key

CryptoKey

Returns

Promise<JsonWebKey>

Overrides

AbstractCryptoEngine.exportKey

Call Signature

exportKey(format, key): Promise<ArrayBuffer>

Export WebCrypto keys to different formats

Parameters
format

"raw" | "pkcs8" | "spki"

key

CryptoKey

Returns

Promise<ArrayBuffer>

Overrides

AbstractCryptoEngine.exportKey

Call Signature

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

Export WebCrypto keys to different formats

Parameters
format

string

key

CryptoKey

Returns

Promise<ArrayBuffer | JsonWebKey>

Overrides

AbstractCryptoEngine.exportKey


fillPublicKeyParameters()

fillPublicKeyParameters(publicKeyInfo, signatureAlgorithm): CryptoEnginePublicKeyParams

Parameters

publicKeyInfo

PublicKeyInfo

signatureAlgorithm

AlgorithmIdentifier

Returns

CryptoEnginePublicKeyParams


generateKey()

Call Signature

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

MDN Reference

Parameters
algorithm

"Ed25519"

extractable

boolean

keyUsages

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

Returns

Promise<CryptoKeyPair>

Inherited from

AbstractCryptoEngine.generateKey

Call Signature

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

Parameters
algorithm

EcKeyGenParams | RsaHashedKeyGenParams

extractable

boolean

keyUsages

KeyUsage[]

Returns

Promise<CryptoKeyPair>

Inherited from

AbstractCryptoEngine.generateKey

Call Signature

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

Parameters
algorithm

AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params

extractable

boolean

keyUsages

KeyUsage[]

Returns

Promise<CryptoKey>

Inherited from

AbstractCryptoEngine.generateKey

Call Signature

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

Parameters
algorithm

AlgorithmIdentifier

extractable

boolean

keyUsages

KeyUsage[]

Returns

Promise<CryptoKeyPair | CryptoKey>

Inherited from

AbstractCryptoEngine.generateKey


getAlgorithmByOID()

Call Signature

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

Gets WebCrypto algorithm by wel-known OID

Type Parameters

T extends Algorithm = Algorithm

Parameters
oid

string

algorithm identifier

safety?

boolean

if true throws exception on unknown algorithm identifier

target?

string

name of the target

Returns

object | T

Returns WebCrypto algorithm or an empty object

Overrides

AbstractCryptoEngine.getAlgorithmByOID

Call Signature

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

Gets WebCrypto algorithm by wel-known OID

Type Parameters

T extends Algorithm = Algorithm

Parameters
oid

string

algorithm identifier

safety

true

if true throws exception on unknown algorithm identifier

target?

string

name of the target

Returns

T

Returns WebCrypto algorithm

Throws

Throws Error exception if unknown algorithm identifier

Overrides

AbstractCryptoEngine.getAlgorithmByOID


getAlgorithmParameters()

getAlgorithmParameters(algorithmName, operation): CryptoEngineAlgorithmParams

Get default algorithm parameters for each kind of operation

Parameters

algorithmName

string

Algorithm name to get common parameters for

operation

CryptoEngineAlgorithmOperation

Kind of operation: "sign", "encrypt", "generateKey", "importKey", "exportKey", "verify"

Returns

CryptoEngineAlgorithmParams

Overrides

AbstractCryptoEngine.getAlgorithmParameters


getHashAlgorithm()

getHashAlgorithm(signatureAlgorithm): string

Getting hash algorithm by signature algorithm

Parameters

signatureAlgorithm

AlgorithmIdentifier

Signature algorithm

Returns

string

Overrides

AbstractCryptoEngine.getHashAlgorithm


getOIDByAlgorithm()

getOIDByAlgorithm(algorithm, safety, target?): string

Get OID for each specific algorithm

Parameters

algorithm

Algorithm

WebCrypto Algorithm

safety

boolean = false

If true throws exception on unknown algorithm. Default is false

target?

string

Name of the target

Returns

string

Throws

Throws Error exception if unknown WebCrypto algorithm

Overrides

AbstractCryptoEngine.getOIDByAlgorithm


getPublicKey()

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

Parameters

publicKeyInfo

PublicKeyInfo

signatureAlgorithm

AlgorithmIdentifier

parameters?

CryptoEnginePublicKeyParams

Returns

Promise<CryptoKey>

Overrides

AbstractCryptoEngine.getPublicKey


getRandomValues()

getRandomValues<T>(array): T

Type Parameters

T extends null | ArrayBufferView

Parameters

array

T

Returns

T

Inherited from

AbstractCryptoEngine.getRandomValues


getSignatureParameters()

getSignatureParameters(privateKey, hashAlgorithm): Promise<CryptoEngineSignatureParams>

Get signature parameters by analyzing private key algorithm

Parameters

privateKey

CryptoKey

The private key user would like to use

hashAlgorithm

string = "SHA-1"

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

Returns

Promise<CryptoEngineSignatureParams>

Overrides

AbstractCryptoEngine.getSignatureParameters


importKey()

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

MDN Reference

Parameters

format

KeyFormat

keyData

BufferSource | JsonWebKey

algorithm

AlgorithmIdentifier

extractable

boolean

keyUsages

KeyUsage[]

Returns

Promise<CryptoKey>

Overrides

AbstractCryptoEngine.importKey


sign()

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

MDN Reference

Parameters

algorithm

EcdsaParams | AlgorithmIdentifier | RsaPssParams

key

CryptoKey

data

BufferSource

Returns

Promise<ArrayBuffer>

Inherited from

AbstractCryptoEngine.sign


signWithPrivateKey()

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

Sign data with pre-defined private key

Parameters

data

BufferSource

Data to be signed

privateKey

CryptoKey

Private key to use

parameters

CryptoEngineSignWithPrivateKeyParams

Parameters for used algorithm

Returns

Promise<ArrayBuffer>

Overrides

AbstractCryptoEngine.signWithPrivateKey


stampDataWithPassword()

stampDataWithPassword(parameters): Promise<ArrayBuffer>

Stamping (signing) data using algorithm similar to HMAC

Parameters

parameters

CryptoEngineStampDataWithPasswordParams

Returns

Promise<ArrayBuffer>

Overrides

AbstractCryptoEngine.stampDataWithPassword


unwrapKey()

Call Signature

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

MDN Reference

Parameters
format

KeyFormat

wrappedKey

BufferSource

unwrappingKey

CryptoKey

unwrapAlgorithm

AesCbcParams | AesCtrParams | AesGcmParams | AlgorithmIdentifier | RsaOaepParams

unwrappedKeyAlgorithm

AesKeyAlgorithm | EcKeyImportParams | AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams

extractable

boolean

keyUsages

KeyUsage[]

Returns

Promise<CryptoKey>

Inherited from

AbstractCryptoEngine.unwrapKey

Call Signature

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

MDN Reference

Parameters
format

KeyFormat

wrappedKey

BufferSource

unwrappingKey

CryptoKey

unwrapAlgorithm

AesCbcParams | AesCtrParams | AesGcmParams | AlgorithmIdentifier | RsaOaepParams

unwrappedKeyAlgorithm

AesKeyAlgorithm | EcKeyImportParams | AlgorithmIdentifier | HmacImportParams | RsaHashedImportParams

extractable

boolean

keyUsages

Iterable<KeyUsage>

Returns

Promise<CryptoKey>

Inherited from

AbstractCryptoEngine.unwrapKey


verify()

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

MDN Reference

Parameters

algorithm

EcdsaParams | AlgorithmIdentifier | RsaPssParams

key

CryptoKey

signature

BufferSource

data

BufferSource

Returns

Promise<boolean>

Inherited from

AbstractCryptoEngine.verify


verifyDataStampedWithPassword()

verifyDataStampedWithPassword(parameters): Promise<boolean>

Parameters

parameters

CryptoEngineVerifyDataStampedWithPasswordParams

Returns

Promise<boolean>

Overrides

AbstractCryptoEngine.verifyDataStampedWithPassword


verifyWithPublicKey()

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

Verify data with the public key

Parameters

data

BufferSource

Data to be verified

signature

Signature value

OctetString | BitString

publicKeyInfo

PublicKeyInfo

Public key information

signatureAlgorithm

AlgorithmIdentifier

Signature algorithm

shaAlgorithm?

string

Hash algorithm

Returns

Promise<boolean>

Overrides

AbstractCryptoEngine.verifyWithPublicKey


wrapKey()

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

MDN Reference

Parameters

format

KeyFormat

key

CryptoKey

wrappingKey

CryptoKey

wrapAlgorithm

AesCbcParams | AesCtrParams | AesGcmParams | AlgorithmIdentifier | RsaOaepParams

Returns

Promise<ArrayBuffer>

Inherited from

AbstractCryptoEngine.wrapKey