Last active
September 3, 2018 22:30
-
-
Save jkyberneees/66d2fd832be4d785f0cc0ceb3e4392c7 to your computer and use it in GitHub Desktop.
decrypt-tweetnacl.js
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') | |
| // 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