Copy/Paste DH Handshake

MJS 2015-09-10

Diffie - Hellman key exchange[0] is a system to generate a shared secret over a public channel. This implementation is a demo, and not to be used with sincerity. But it does work and can be fun.

This is your half to sent to the other person:

Paste what they send to you below:

Then make your shared secret:

This is your shared secret, use it to derive other keys:

You can test this yourself by opening two browser windows and copying/pasting between them.


Big Integer Library[1] is used to handle all the numbers javascript can't. It also does the heavy lifting of power, modulo arithmetic. The random numbers are acquired from the new (ish) native crypto API in firefox and chrome[2]. The prime is 512 bits from Sebastian Schaetz's[3] running of the Crypto++[4] DH prime group generator. The algorithm used here is heavily influenced by Schaetz work.