justin.m.chase justin.m.chase - 1 month ago 13
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:
https://nodejs.org/api/crypto.html#crypto_crypto_getdiffiehellman_group_name

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

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

Answer

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.