Yay! My patch implementing support for Diffie-Hellman key exchange in Node.js has finally been merged into the Node.js master branch. This will simplify the OpenID for Node.js codebase a lot. It will also make the OpenID association phase run a lot faster, since the current code does Diffie-Hellman in Javascript while the Node.js crypto version does it all in native code using OpenSSL.
A brief API overview:
crypto.createDiffieHellman(prime_length)- Creates a Diffie-Hellman key exchange object and generates a prime of the given bit length. The generator used is
2.
- Creates a Diffie-Hellman key exchange object and generates a prime of the given bit length. The generator used is
crypto.createDiffieHellman(prime, encoding='binary')- Creates a Diffie-Hellman key exchange object using the supplied prime. The generator used is
2. Encoding can be'binary','hex', or'base64'.
- Creates a Diffie-Hellman key exchange object using the supplied prime. The generator used is
diffieHellman.generateKeys(encoding='binary')- Generates private and public Diffie-Hellman key values, and returns the public key in the specified encoding. This key should be transferred to the other party. Encoding can be
'binary','hex', or'base64'.
- Generates private and public Diffie-Hellman key values, and returns the public key in the specified encoding. This key should be transferred to the other party. Encoding can be
diffieHellman.computeSecret(other_public_key, input_encoding='binary', output_encoding=input_encoding)- Computes the shared secret using
other_public_keyas the other party’s public key and returns the computed shared secret. Supplied key is interpreted using specifiedinput_encoding, and secret is encoded using specifiedoutput_encoding. Encodings can be'binary','hex', or'base64'. If no output encoding is given, the input encoding is used as output encoding.
- Computes the shared secret using
diffieHellman.getPrime(encoding='binary')- Returns the Diffie-Hellman prime in the specified encoding, which can be
'binary','hex', or'base64'.
- Returns the Diffie-Hellman prime in the specified encoding, which can be
diffieHellman.getGenerator(encoding='binary')- Returns the Diffie-Hellman prime in the specified encoding, which can be
'binary','hex', or'base64'.
- Returns the Diffie-Hellman prime in the specified encoding, which can be
diffieHellman.getPublicKey(encoding='binary')- Returns the Diffie-Hellman public key in the specified encoding, which can be
'binary','hex', or'base64'.
- Returns the Diffie-Hellman public key in the specified encoding, which can be
diffieHellman.getPrivateKey(encoding='binary')- Returns the Diffie-Hellman private key in the specified encoding, which can be
'binary','hex', or'base64'.
- Returns the Diffie-Hellman private key in the specified encoding, which can be
diffieHellman.setPublicKey(public_key, encoding='binary')- Sets the Diffie-Hellman public key. Key encoding can be
'binary','hex', or'base64'.
- Sets the Diffie-Hellman public key. Key encoding can be
diffieHellman.setPrivateKey(public_key, encoding='binary')- Sets the Diffie-Hellman private key. Key encoding can be
'binary','hex', or'base64'.
- Sets the Diffie-Hellman private key. Key encoding can be
NOTE: The API is still subject to change.
I would appreciate getting a note if you actually do something useful with it.
Play around with it and let me know what you think!