I'm trying to implement a diffie-hellman-group1-sha1 key exchange for my node.js implemenation of the SSH protocol.
I want to use the built in crypto module for this. My code:
var hellman = crypto.createDiffieHellman(
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"+
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD"+
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"+
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"+
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381"+
"FFFFFFFFFFFFFFFF","hex");
hellman.setPrivateKey(crypto.randomBytes(20));
hellman.generateKeys();
But node.js can't execute it. It throws the following error: "Error: Not initialized"
Does anyone know what's going wrong?
It seems to be a bug of node.js: https://github.com/joyent/node/issues/2338
Node version 7.5 has included a solution to this, where one can get predefined diffieHellmans using crypto.getDiffieHellman("modp2");
It was added in the following push request: https://github.com/joyent/node/pull/2638
All predefined diffie hellmans can be watched here: https://gist.github.com/1899353