// node.js 0.5 Diffie-Hellman example
var crypto = require("crypto");
// the prime is shared by everyone
var server = crypto.createDiffieHellman(512);
var prime = server.getPrime();
// sharing secret key on a pair
var alice = crypto.createDiffieHellman(prime);
alice.generateKeys();
var alicePub = alice.getPublicKey();
var bob = crypto.createDiffieHellman(prime);
bob.generateKeys();
var bobPub = bob.getPublicKey();
var bobAliceSecret = bob.computeSecret(alicePub);
var aliceBobSecret = alice.computeSecret(bobPub);
I am trying to understand how to use the NodeJS crypto library for a diffie-hellman implementation, and got the above code to compute a shared secret. The problem is both Alice and Bob generate their keys after getting the shared prime. I need them to generate their respective key pairs without having to use any shared information, later than can use shared information to compute the shared secret. I can't get to see how that can be done using the NodeJS crypto library.
var alice = crypto.createDiffieHellman(1024);alice.generateKeys();var alicePub = alice.getPublicKey();var bob = crypto.createDiffieHellman(1024);bob.generateKeys();var bobPub = bob.getPublicKey();var bobAliceSecret = bob.computeSecret(alicePub);var aliceBobSecret = alice.computeSecret(bobPub);The above does not allow alice and bob to compute the same shared secret. - user820955