UNPKG

js-chacha8

Version:

Pure JavaScript ChaCha8 stream cipher

44 lines (32 loc) 1.18 kB
# JS-ChaCha8 Pure JavaScript ChaCha8 stream cipher ### Description This repository is changed from [thesimj/js-chacha20](https://github.com/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 ```javascript 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 ```javascript 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.