編輯

共用方式為


BrowserCrypto class

This class implements functions used by the browser library to perform cryptography operations such as hashing and encoding. It also has helper functions to validate the availability of specific APIs.

Constructors

BrowserCrypto(Logger, CryptoOptions)

Methods

exportJwk(CryptoKey)

Export key as Json Web Key (JWK)

generateKeyPair(boolean, Array<KeyUsage>)

Generates a keypair based on current keygen algorithm config.

getRandomValues(Uint8Array)

Populates buffer with cryptographically random values.

importJwk(JsonWebKey, boolean, Array<KeyUsage>)

Imports key as Json Web Key (JWK), can set extractable and usages.

sha256Digest(string)

Returns a sha-256 hash of the given dataString as an ArrayBuffer.

sign(CryptoKey, ArrayBuffer)

Signs given data with given key

Constructor Details

BrowserCrypto(Logger, CryptoOptions)

new BrowserCrypto(logger: Logger, cryptoOptions?: CryptoOptions)

Parameters

logger

Logger

cryptoOptions
CryptoOptions

Method Details

exportJwk(CryptoKey)

Export key as Json Web Key (JWK)

function exportJwk(key: CryptoKey): Promise<JsonWebKey>

Parameters

key

CryptoKey

Returns

Promise<JsonWebKey>

generateKeyPair(boolean, Array<KeyUsage>)

Generates a keypair based on current keygen algorithm config.

function generateKeyPair(extractable: boolean, usages: Array<KeyUsage>): Promise<CryptoKeyPair>

Parameters

extractable

boolean

usages

Array<KeyUsage>

Returns

Promise<CryptoKeyPair>

getRandomValues(Uint8Array)

Populates buffer with cryptographically random values.

function getRandomValues(dataBuffer: Uint8Array): Uint8Array

Parameters

dataBuffer

Uint8Array

Returns

Uint8Array

importJwk(JsonWebKey, boolean, Array<KeyUsage>)

Imports key as Json Web Key (JWK), can set extractable and usages.

function importJwk(key: JsonWebKey, extractable: boolean, usages: Array<KeyUsage>): Promise<CryptoKey>

Parameters

key

JsonWebKey

extractable

boolean

usages

Array<KeyUsage>

Returns

Promise<CryptoKey>

sha256Digest(string)

Returns a sha-256 hash of the given dataString as an ArrayBuffer.

function sha256Digest(dataString: string): Promise<ArrayBuffer>

Parameters

dataString

string

Returns

Promise<ArrayBuffer>

sign(CryptoKey, ArrayBuffer)

Signs given data with given key

function sign(key: CryptoKey, data: ArrayBuffer): Promise<ArrayBuffer>

Parameters

key

CryptoKey

data

ArrayBuffer

Returns

Promise<ArrayBuffer>