I am using crypto module of node js for exchanging key using diffie-hellman algorithm.
server.js
const crypto = require("crypto");
const alice = crypto.createDiffieHellman(512);
const aliceKey = alice.generateKeys();
client.js
const bob = crypto.createDiffieHellman(alice.getPrime(), alice.getGenerator());
const bobKey = bob.generateKeys();
const aliceSecret = alice.computeSecret(bobKey);
const bobSecret = bob.computeSecret(aliceKey);
The above example is taken from node.js documentation as shown the client uses servers prime number for generating the prime number.
my question is how should I securely send the prime number and the other parameter to client over internet? are there any other alternatives?
and another question is that I am generating keys using generate keys function but I have already generated private-key.pem and public-cert.pem file. can I use those if yes then how?, if no then what is difference between those keys?
openssl genrsa
. For DH, useopenssl genpkey
. For ECDH, useopenssl ecparam
.