EC Key Exchange & Encryption

Generate Elliptic Curve key pairs for Alice and Bob, compute shared secrets using ECDH, and encrypt/decrypt messages

Generate EC Key Pairs
Alice's Keys
Bob's Keys
Encrypt / Decrypt
Encryption: Uses Alice's Private Key + Bob's Public Key
Result

Enter a message above and click Process to see the result

Understanding EC Key Exchange (ECDH) - Complete Guide
What is ECDH?

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!

The Magic: Alice and Bob can compute the SAME secret key without ever transmitting it. They only exchange public keys, which are useless to attackers.
How ECDH Works (Step-by-Step)
1
Key Generation

Alice and Bob each generate their own EC key pair (private + public key)

Private Public
2
Exchange Public Keys

Alice sends her public key to Bob. Bob sends his public key to Alice.

3
Compute Shared Secret

Each computes the secret using their private key + other's public key

S = priv * Pub
4
Encrypt/Decrypt

Use the shared secret as an AES key to encrypt and decrypt messages

The Math (Simplified)

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:

  • Alice computes: S = a * B = a * (b * G) = ab * G
  • Bob computes: S = b * A = b * (a * G) = ab * G
Both get the same point ab * G on the curve!
Why Is It Secure?

Elliptic Curve Discrete Logarithm Problem (ECDLP):

  • Easy: Given a and G, compute A = a * G
  • Hard: Given A and G, find a
Attacker sees: Public keys A and B, base point G
Attacker cannot compute: a or b (private keys), therefore cannot compute ab * G (shared secret)
EC Curves Comparison
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
Real-World Applications
TLS/HTTPS Secures 70%+ of web traffic
Cryptocurrencies Bitcoin, Ethereum wallets
Messaging Apps Signal, WhatsApp E2E encryption
SSH Keys Ed25519 keys for servers
OpenSSL Commands
# 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!"
Security Best Practices
DO
  • Use P-256 or higher
  • Generate fresh key pairs
  • Use secure random generator
  • Derive keys with KDF (HKDF)
  • Validate public keys
DON'T
  • Reuse ephemeral keys
  • Share private keys
  • Use weak curves (<224 bit)
  • Skip key validation
  • Use raw shared secret
Pro Tip: Always use a Key Derivation Function (KDF) like HKDF to derive encryption keys from the shared secret, never use it directly!
ECDH vs RSA Key Exchange
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)

Support This Free Tool

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.

500K+ users
200+ tools
100% private
Privacy Guarantee: Private keys you enter or generate are never stored on our servers. All tools are served over HTTPS.