Skip to content

Instantly share code, notes, and snippets.

@jkyberneees
Last active April 15, 2020 10:14
Show Gist options
  • Select an option

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

Select an option

Save jkyberneees/f091d3ef516653b73a3e4bd5a5642889 to your computer and use it in GitHub Desktop.
const nacl = require('tweetnacl')
nacl.util = require('tweetnacl-util')
// generating key pairs
const bob = nacl.box.keyPair()
const alice = nacl.box.keyPair()
// generating one time nonce for encryption
const nonce = nacl.randomBytes(24)
// message for Alice
const utf8 = 'Hello Alice'
// Bob encrypts message for Alice
const box = nacl.box(
nacl.util.decodeUTF8(utf8),
nonce,
alice.publicKey,
bob.secretKey
)
// somehow send this message to Alice
const message = {box, nonce}
@jkyberneees
Copy link
Author

Generating key pairs:

const { publicKey, secretKey } = nacl.box.keyPair()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment