asymmetric-crypto
Encryption and signing using public-key cryptography (via tweetnacl
)
Install
npm install asymmetric-crypto
This module can be used for Node.js as well as browsers using Browserify.
Usage
const crypto = require('asymmetric-crypto')
const keyPair = crypto.keyPair()
const newKeyPair = crypto.fromSecretKey(keyPair.secretKey)
const myKeyPair = crypto.keyPair()
const theirKeyPair = crypto.keyPair()
const encrypted = crypto.encrypt('some data', theirKeyPair.publicKey, myKeyPair.secretKey)
const decrypted = crypto.decrypt(encrypted.data, encrypted.nonce, myKeyPair.publicKey, theirKeyPair.secretKey)
const message = 'some message'
const signature = crypto.sign(message, myKeyPair.secretKey)
const validSignature = crypto.verify(message, signature, myKeyPair.publicKey)
Tests
npm test
Internals
tweetnacl
for the cryptographic implementationtweetnacl-util
for converting into / from stringsed2curve
for converting Ed25519 keys into curve25519-xsalsa20-poly1305 keys (so you can encrypt and sign with the same key pair)fast-memoize
to make converting keys more efficient
Licence
MIT
Thanks to @pguth for the inspiration. :smile: