Generate Elliptic Curve key pairs for Alice and Bob, compute shared secrets using ECDH, and encrypt/decrypt messages
Enter a message above and click Process to see the result
Elliptic Curve Diffie-Hellman (ECDH) is a key agreement protocol that allows two parties (Alice and Bob) to establish a shared secret over an insecure channel - even if an attacker is watching all their communications!
Alice and Bob each generate their own EC key pair (private + public key)
Alice sends her public key to Bob. Bob sends his public key to Alice.
Each computes the secret using their private key + other's public key
S = priv * Pub
Use the shared secret as an AES key to encrypt and decrypt messages
Setup: Both parties agree on a curve and base point G
| Alice | Private: a (random number) |
Public: A = a * G |
| Bob | Private: b (random number) |
Public: B = b * G |
Shared Secret Computation:
S = a * B = a * (b * G) = ab * GS = b * A = b * (a * G) = ab * Gab * G on the curve!
Elliptic Curve Discrete Logarithm Problem (ECDLP):
a and G, compute A = a * GA and G, find aA and B, base point G
a or b (private keys), therefore cannot compute ab * G (shared secret)
| Curve | Key Size | Security | RSA Equivalent | Common Use |
|---|---|---|---|---|
| P-256 | 256 bits | 128-bit | ~3072-bit RSA | TLS 1.3, Web PKI |
| P-384 | 384 bits | 192-bit | ~7680-bit RSA | Government, Finance |
| P-521 | 521 bits | 256-bit | ~15360-bit RSA | Top Secret, Long-term |
| secp256k1 | 256 bits | 128-bit | ~3072-bit RSA | Bitcoin, Ethereum |
| Curve25519 | 256 bits | 128-bit | ~3072-bit RSA | Signal, SSH, WireGuard |
| brainpoolP256r1 | 256 bits | 128-bit | ~3072-bit RSA | EU Government, German BSI |
# Generate Alice's key pair
openssl ecparam -genkey -name prime256v1 -out alice_priv.pem
openssl ec -in alice_priv.pem -pubout -out alice_pub.pem
# Generate Bob's key pair
openssl ecparam -genkey -name prime256v1 -out bob_priv.pem
openssl ec -in bob_priv.pem -pubout -out bob_pub.pem
# Alice derives shared secret
openssl pkeyutl -derive -inkey alice_priv.pem \
-peerkey bob_pub.pem -out alice_secret.bin
# Bob derives shared secret (same result!)
openssl pkeyutl -derive -inkey bob_priv.pem \
-peerkey alice_pub.pem -out bob_secret.bin
# Verify both secrets are identical
diff alice_secret.bin bob_secret.bin && echo "Secrets match!"
| Aspect | ECDH | RSA |
|---|---|---|
| Key Size for 128-bit Security | 256 bits | 3072 bits |
| Performance | 10-20x faster | Slower (large modular exponentiation) |
| Forward Secrecy | Yes (with ephemeral keys) | No (unless using RSA-DHE) |
| Mobile/IoT Friendly | Excellent | Resource intensive |
| Quantum Resistance | No (use post-quantum) | No (use post-quantum) |
Every coffee helps keep the servers running. Every book sale funds the next tool I'm dreaming up. You're not just supporting a site — you're helping me build what developers actually need.