Created
November 12, 2016 16:19
-
-
Save perry-mitchell/0d4a1da2348eac2bbd9dcd5761c3877c to your computer and use it in GitHub Desktop.
Revisions
-
perry-mitchell created this gist
Nov 12, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ // To use this, you will need to `npm install iocane`! const crypto = require("crypto"); let aliceECDH = crypto.createECDH("secp256k1"); aliceECDH.generateKeys(); let alicePublicKey = aliceECDH.getPublicKey(null, "compressed"), alicePrivateKey = aliceECDH.getPrivateKey(null, "compressed"); console.log("Alice Public: ", alicePublicKey.length, alicePublicKey.toString("hex")); console.log("Alice Private:", alicePrivateKey.length, alicePrivateKey.toString("hex")); let bobECDH = crypto.createECDH("secp256k1"); bobECDH.generateKeys(); let bobPublicKey = bobECDH.getPublicKey(null, "compressed"), bobPrivateKey = bobECDH.getPrivateKey(null, "compressed"); console.log("Bob Public: ", bobPublicKey.length, bobPublicKey.toString("hex")); console.log("Bob Private: ", bobPrivateKey.length, bobPrivateKey.toString("hex")); // On Alice's side let secret1 = aliceECDH.computeSecret(bobPublicKey); console.log("Alice Secret: ", secret1.length, secret1.toString("hex")); // On Bob's side let secret2 = bobECDH.computeSecret(alicePublicKey); console.log("Bob Secret: ", secret2.length, secret2.toString("hex")); const iocane = require("iocane").crypto; iocane .encryptWithPassword("Hi there, Bob!", secret1) .then(function(encrypted) { console.log("Encrypted:", encrypted); // send to Bob iocane .decryptWithPassword(encrypted, secret1) .then(function(message) { console.log("Decrypted:", message); }); });