sodium-encryption
Sodium encryption that works in node and in the browser
npm install sodium-encryption
Usage
var encryption =var key = encryptionvar nonce = encryptionvar message =var box = encryptionconsoleconsole
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 = encryptionvar otherKeys = encryptionconsoleconsole
License
MIT