js-chacha8
Version:
Pure JavaScript ChaCha8 stream cipher
44 lines (32 loc) • 1.18 kB
Markdown
Pure JavaScript ChaCha8 stream cipher
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.
```
npm install js-chacha8 --save
```
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.