libsodium chacha20 symmetric encryption stream
npm install chacha-streamThis module provides encryption and decryption streams for the sodium chacha20
implementation. It can be used to encrypt channels using a key already known to
both sides.
It manages communicating the stream nonce to the remote side, which is
transmitted in plaintext. This is safe information to leak (the nonce is used
to detect replay attacks).
``js
const chacha = require('chacha-stream')
const through = require('through2')
const crypto = require('crypto')
function printer (prefix) {
return through(function (chunk, enc, next) {
console.log(prefix, chunk.toString())
next(null, chunk)
})
}
let key = crypto.randomBytes(32)
let encode0 = chacha.encoder(key)
let decode0 = chacha.decoder(key)
encode0.write('hello world')
encode0.pipe(printer('encrypted')).pipe(decode0).pipe(printer('decrypted'))
`
outputs
``
encrypted }�?�lx
encrypted z>��Un��4�
decrypted hello world
`js`
var chacha = require('chacha-stream')
Creates a Transform stream that accepts plaintexts written to it, and outputs encrypted ciphertext.
key is a 32-byte Buffer.
Creates a Transform stream that accepts ciphertext written to it, and outputs decrypted plaintext.
key is a 32-byte Buffer.
With npm installed, run
```
$ npm install chacha-stream
ISC