Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 538
justin.m.chase Avatar asked Nov 15 '25 20:11

justin.m.chase


1 Answers

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.

like image 170
ralh Avatar answered Nov 17 '25 16:11

ralh