sodium-universal

Universal wrapper for sodium-javascript and sodium-native working in Node.js and the Browser

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
sodium-universal
6754.0.12 months ago7 years agoMinified + gzip package size for sodium-universal in KB

Readme

sodium-universal
Universal wrapper for sodium-javascript and sodium-native working in Node.js and the Browser
npm install sodium-universal

sodium-native ships with prebuilds for macOS, Windows, and Linux.
Note that the module itself is generated on a prepublish hook.

Usage

var sodium = require('sodium-universal')

var rnd = Buffer.allocUnsafe(12) // Cryptographically random data
sodium.randombytes_buf(rnd)

console.log(rnd.toString('hex'))

Works seamlessly with Node.js:
$ node example.js
c7dbd46a6cc84ff2e0d1285c

And the browser:
First install the peer dep, sodium-javascript.
npm install --save sodium-javascript

And then browserify
browserify example.js > bundle.js

Introduction

libsodium is a collection of cryptographic primitives, providing a low-level foundation to build higher-level cryptographic applications and protocols. It is often put in contrast to RSA based cryptography and OpenSSL, even though they all share overlapping algorithms and target slightly different audiences. Sodium is a collection of modern collection of primitives, fulfilling the same cryptographic tasks, but based on simpler and more efficient algorithms.
This library provides seamless bindings to sodium-native, which is the original C implementation of libsodium exposed as a Node native module. For the browser we expose sodium-javascript, using the package.json browser field, which is supported by most bundlers.

API

Please refer to sodium-native and sodium-javascript. Note that the two modules do not yet have feature parity, where sodium-native is the more featureful of the two.

Compatibilty