Skip to content

Instantly share code, notes, and snippets.

@jkyberneees
Last active September 5, 2018 09:11
Show Gist options
  • Select an option

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

Select an option

Save jkyberneees/9e21c8ed38d059e3424145e51dea7263 to your computer and use it in GitHub Desktop.
// Bob precomputes shared key with Alice (one time)
const sharedKey = nacl.box.before(alice.publicKey, bob.secretKey)
// generating one time nonce for encryption
const nonce = nacl.randomBytes(24)
// Bob encrypt message for Alice
const box = nacl.box.after(
nacl.util.decodeUTF8('Hello Alice'),
nonce,
sharedKey // <-- using shared key
)
const message = {box, nonce}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment