Title: Elliptic curve Diffie-Hellman example Post by: mndrix on April 12, 2013, 06:27:25 PM Diffie-Hellman key agreement is really easy using elliptic curves. Maybe because of that, I was unable to find a good, working example with which to experiment, so I wrote one: 32 lines of Go (https://gist.github.com/mndrix/5373519). It should be equally short for any other language that has a decent EC math library.
Here's a sample run:
The first 4 lines show Alice and Bob's private and public keys, respectively. The final 2 lines show that they each calculate the same shared secret. The example uses curve P-224 instead of secp256k1 since the former is part of Go's library. |