justin.m.chase justin.m.chase - 2 months ago 27
Node.js Question

How do I actually encrypt something with the Diffie-Hellman apis in nodejs?

I'm looking at the very simple demo in the nodejs crypto documentation here:

They very easily demonstrate how to get a shared secret... now what?

How can I use said shared secret to encrypt and decrypt data?


Diffie-Hellman is a key exchange algorithm. It does not provide encryption by itself.

After both parties have established a common secret through D-H, you can use that as a key in a symmetrical encryption algorithm like AES.

The secret can be used for example as a password for https://nodejs.org/api/crypto.html#crypto_crypto_createcipher_algorithm_password

Mind the security note at the end.