Universal wrapper for
sodium-native working in Node.js and the Browser
npm install sodium-universal
sodium-native ships with prebuilds for macOS, Windows, and Linux.
If for whatever reason it cannot load the native module,
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:
browserify example.js > bundle.js
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
browser field, which is supported by most bundlers.