sodium-native
Low level bindings for libsodium
Last updated 7 years ago by emilbayes .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install sodium-native 
SYNC missed versions from official npm registry.

sodium-native

build status

Low level bindings for libsodium.

npm install sodium-native

The goal of this project is to be thin, stable, unopionated wrapper around libsodium.

All methods exposed are more or less a direct translation of the libsodium c-api. This means that most data types are buffers and you have to manage allocating return values and passing them in as arguments intead of receiving them as return values.

This makes this API harder to use than other libsodium wrappers out there, but also means that you'll be able to get a lot of perf / memory improvements as you can do stuff like inline encryption / decryption, re-use buffers etc.

This also makes this library useful as a foundation for more high level crypto abstractions that you want to make.

Usage

var sodium = require('sodium-native')

var nonce = Buffer.alloc(sodium.crypto_secretbox_NONCEBYTES)
var key = sodium.sodium_malloc(sodium.crypto_secretbox_KEYBYTES) // secure buffer
var message = Buffer.from('Hello, World!')
var ciphertext = Buffer.alloc(message.length + sodium.crypto_secretbox_MACBYTES)

sodium.randombytes_buf(nonce) // insert random data into nonce
sodium.randombytes_buf(key)  // insert random data into key

// encrypted message is stored in ciphertext.
sodium.crypto_secretbox_easy(ciphertext, message, nonce, key)

console.log('Encrypted message:', ciphertext)

var plainText = Buffer.alloc(ciphertext.length - sodium.crypto_secretbox_MACBYTES)

if (!sodium.crypto_secretbox_open_easy(plainText, ciphertext, nonce, key)) {
  console.log('Decryption failed!')
} else {
  console.log('Decrypted message:', plainText, '(' + plainText.toString() + ')')
}

Documentation

Complete documentation may be found on the sodium-friends website

License

MIT

Current Tags

  • 4.0.5                                ...           latest (9 months ago)
  • 2.4.6                                ...           nightly (5 years ago)

60 Versions

  • 4.0.5                                ...           9 months ago
  • 4.0.4                                ...           a year ago
  • 4.0.3                                ...           a year ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           2 years ago
  • 4.0.0                                ...           2 years ago
  • 3.4.1                                ...           2 years ago
  • 3.4.0                                ...           2 years ago
  • 3.3.0                                ...           3 years ago
  • 3.2.1                                ...           4 years ago
  • 3.2.0                                ...           4 years ago
  • 3.1.1                                ...           4 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.4.9                                ...           5 years ago
  • 2.4.6                                ...           5 years ago
  • 2.4.6-rc                                ...           5 years ago
  • 2.4.5                                ...           5 years ago
  • 2.4.4                                ...           5 years ago
  • 2.4.3                                ...           5 years ago
  • 2.4.2                                ...           5 years ago
  • 2.3.0                                ...           6 years ago
  • 2.2.6                                ...           6 years ago
  • 2.2.5                                ...           6 years ago
  • 2.2.4                                ...           6 years ago
  • 2.2.3                                ...           6 years ago
  • 2.2.2                                ...           6 years ago
  • 2.2.1                                ...           6 years ago
  • 2.2.0                                ...           6 years ago
  • 2.1.6                                ...           6 years ago
  • 2.1.5                                ...           7 years ago
  • 2.1.4                                ...           7 years ago
  • 2.1.3                                ...           7 years ago
  • 2.1.2                                ...           7 years ago
  • 2.1.1                                ...           7 years ago
  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.10.3                                ...           7 years ago
  • 1.10.2                                ...           7 years ago
  • 1.10.1                                ...           7 years ago
  • 1.10.0                                ...           7 years ago
  • 1.9.0                                ...           7 years ago
  • 1.8.0                                ...           8 years ago
  • 1.7.0                                ...           8 years ago
  • 1.6.0                                ...           8 years ago
  • 1.5.1                                ...           8 years ago
  • 1.5.0                                ...           8 years ago
  • 1.4.1                                ...           8 years ago
  • 1.4.0                                ...           8 years ago
  • 1.3.3                                ...           8 years ago
  • 1.3.2                                ...           8 years ago
  • 1.3.1                                ...           8 years ago
  • 1.3.0                                ...           8 years ago
  • 1.2.0                                ...           8 years ago
  • 1.1.2                                ...           8 years ago
  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
  • 0.0.1                                ...           8 years ago
  • 0.0.0                                ...           8 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (8)

Copyright 2013 - present © cnpmjs.org | Home |