Socket
Book a DemoInstallSign in
Socket

chacha-stream

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chacha-stream

libsodium chacha20 symmetric encryption stream

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

chacha-stream

This 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).

Usage

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

API

var chacha = require('chacha-stream')

var encoder = chacha.encode(key)

Creates a Transform stream that accepts plaintexts written to it, and outputs encrypted ciphertext.

key is a 32-byte Buffer.

var decoder = chacha.decode(key)

Creates a Transform stream that accepts ciphertext written to it, and outputs decrypted plaintext.

key is a 32-byte Buffer.

Install

With npm installed, run

$ npm install chacha-stream

License

ISC

FAQs

Package last updated on 12 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts