Skip to main content

Class: ChaCha20

Implementation of the ChaCha20 cipher.

Table of contents

Constructors

Methods

Constructors

constructor

new ChaCha20(key, nonce, counter?)

Create a new instance of ChaCha20.

Parameters

NameTypeDefault valueDescription
keyUint8ArrayundefinedThe key.
nonceUint8ArrayundefinedThe nonce.
counternumber0Counter.

Methods

encrypt

encrypt(data): Uint8Array

Encrypt the data.

Parameters

NameTypeDescription
dataUint8ArrayThe source data to encrypt.

Returns

Uint8Array

The encrypted data.


decrypt

decrypt(data): Uint8Array

Decrypt the data.

Parameters

NameTypeDescription
dataUint8ArrayThe source data to decrypt.

Returns

Uint8Array

The decrypted data.


keyStream

keyStream(length): Uint8Array

Create a keystream of the given length.

Parameters

NameTypeDescription
lengthnumberThe length to create the keystream.

Returns

Uint8Array

The keystream.