mpneuried
10/29/2015 - 2:48 PM

Diffie-Hellman Tests in Node

Diffie-Hellman Tests in Node

// Install: "npm i prompt"
// Usage: "node dh.js"

var crypto, dh, prompt;
crypto = require('crypto');
prompt = require('prompt');

dh = crypto.getDiffieHellman('modp5');
dh.generateKeys();

console.log("\nMy Pub:\n", dh.getPublicKey("hex"), "\n");

prompt.start();
prompt.get(['pub'], function(err, result) {
  if (err) {
    console.error(err);
    return;
  }
  console.log("\nSECRET:\n", dh.computeSecret(result.pub, "hex", 'hex'));
});