Skip to content

Instantly share code, notes, and snippets.

@jkyberneees
Last active September 3, 2018 22:30
Show Gist options
  • Select an option

  • Save jkyberneees/66d2fd832be4d785f0cc0ceb3e4392c7 to your computer and use it in GitHub Desktop.

Select an option

Save jkyberneees/66d2fd832be4d785f0cc0ceb3e4392c7 to your computer and use it in GitHub Desktop.
decrypt-tweetnacl.js
const nacl = require('tweetnacl')
nacl.util = require('tweetnacl-util')
// reading Alice key pair from secret key
const alice = nacl.box.keyPair.fromSecretKey(/* Uint8Array with 32-byte secret key */)
// reading Bob public key
const bob = {publicKey: /* Uint8Array with 32-byte secret key */}
// const message = ... the message object from Bob
// Alice decrypts message from Bob
const payload = nacl.box.open(message.box, message.nonce, bob.publicKey, alice.secretKey)
const utf8 = nacl.util.encodeUTF8(payload) // <-- 'Hello Alice'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment