sodium-encryption
Sodium encryption that works in node and in the browser
Last updated 8 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install sodium-encryption 
SYNC missed versions from official npm registry.

sodium-encryption

Sodium encryption that works in node and in the browser

npm install sodium-encryption

build status

Usage

var encryption = require('sodium-encryption')

var key = encryption.key()
var nonce = encryption.nonce()
var message = Buffer('a message')

var box = encryption.encrypt(message, nonce, key)

console.log('encrypted message is:', box)
console.log('decrypted message is:', encryption.decrypt(box, nonce, key))

API

key = encryption.key()

Generate a secret key. Returns a 32 byte buffer.

nonce = encryption.nonce()

Generate a nonce. Returns a 24 byte buffer. A nonce can be public and you should use a new one everytime you use a key.

box = encryption.encrypt(message, nonce, key)

Encrypts a message.

message = encryption.decrypt(box, nonce, key)

Decrypt a message. Returns null is the message cannot be decrypted.

keys = encryption.scalarMultiplicationKeyPair([secretKey])

Generate a key pair to be used for scalar multiplication. If you don't pass in a secret key, one will be generated for you. Returns a key pair consisting of a secret key and a public key.

{
  secretKey: <Buffer>,
  publicKey: <Buffer>
}

sharedKey = encryption.scalarMultiplication(secretKey, otherPublicKey)

Generate a shared key based on a remote public scalar multiplication key and your own secret key. Returns the same shared key if called with corresponding secret and public key

var keys = encryption.scalarMultiplicationKeyPair()
var otherKeys = encryption.scalarMultiplicationKeyPair()

console.log('shared key', encryption.scalarMultiplication(keys.secretKey, otherKeys.publicKey))
console.log('shared key', encryption.scalarMultiplication(otherKeys.secretKey, keys.publicKey))

License

MIT

Current Tags

  • 1.2.3                                ...           latest (8 years ago)

7 Versions

  • 1.2.3                                ...           8 years ago
  • 1.2.2                                ...           8 years ago
  • 1.2.1                                ...           8 years ago
  • 1.2.0                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (2)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |