1.1.0 • Published 1 year ago

js-chacha8 v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

JS-ChaCha8

Pure JavaScript ChaCha8 stream cipher

Description

This repository is changed from thesimj/js-chacha20 and uses the same open source license as the original repository. ChaCha8 is not described here.

Install

npm install js-chacha8 --save

Usage

Encrypt message with key and nonce

import JSChaCha8 from "js-chacha8";

const key = Buffer.alloc(32); // 32 bytes key
const nonce = Buffer.alloc(12); // 12 bytes nonce
const message = Buffer.allloc(64); // some data as bytes array

// Encrypt //
const encrypt = new JSChaCha8(key, nonce).encrypt(message);

// now encrypt contains buffer of encrypted message

Decrypt encrypted message with key and nonce

import JSChaCha8 from "js-chacha8";

const key = Buffer.alloc(32); // 32 bytes key
const nonce = Buffer.alloc(12); // 12 bytes nonce
const message = Buffer.allloc(64); // some data as bytes array

// Encrypt //
const message = new JSChaCha8(key, nonce).decrypt(encrypt);

// now message contains bufffer of original message

That all. If something happens, Error will be thrown. More examples you can find in tests files.