Last active
September 3, 2018 22:08
-
-
Save jkyberneees/47c65609685e915b0c9e0ade43187978 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const nacl = require('tweetnacl') | |
| nacl.util = require('tweetnacl-util') | |
| // generating Bob key pair | |
| const bob = nacl.box.keyPair() | |
| // generating Alice key pair | |
| const alice = nacl.box.keyPair() | |
| // generating one time nonce for encryption | |
| const nonce = nacl.randomBytes(24) | |
| // Bob encrypt message for Alice (only requires Alice public key) | |
| const utf8 = 'Hello Alice' | |
| const box = nacl.box( | |
| nacl.util.decodeUTF8(utf8), | |
| nonce, | |
| alice.publicKey, | |
| bob.secretKey | |
| ) | |
| const message = {box, nonce} // somehow send this message to Alice | |
| // Alice decrypt message from Bob (only requires Bob public key) | |
| const payload = nacl.box.open(message.box, message.nonce, bob.publicKey, alice.secretKey) | |
| // assert.equal(utf8, nacl.util.encodeUTF8(payload)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment