Calculation history
History stores public parameters and status locally. Private keys are never saved by this page. Clear records whenever they are no longer needed.
Formula used
| Result | Formula |
|---|---|
| Alice public key | A = ga mod p |
| Bob public key | B = gb mod p |
| Alice shared secret | SA = Ba mod p |
| Bob shared secret | SB = Ab mod p |
| Verification | SA = SB |
How to use
Select a calculation mode and parameter preset. Enter the modulus, generator, and available keys. Choose output and validation options before calculating.
Review both public keys and shared secrets. Confirm the verification result shows matching values. Study warnings before reusing any parameters elsewhere.
Use attack demonstrations only with tiny educational examples. Never paste live private keys into web tools. Production systems require reviewed cryptographic libraries.
Example data
| Example | p | g | Alice private | Bob private | Expected secret |
|---|---|---|---|---|---|
| Classroom | 23 | 5 | 6 | 15 | 2 |
| Secondary | 47 | 5 | 9 | 13 | 22 |
Security notes
Diffie-Hellman establishes a shared secret across an exposed channel. It does not authenticate either participant alone. Authentication must protect against active interception attacks.
Small moduli permit practical discrete-log attacks. Weak generators can create dangerous subgroups. Modern deployments use approved groups and strict validation.
The raw secret should enter a key derivation function. Session keys need context and fresh salt. Never reuse private exponents across unrelated sessions.
Frequently asked questions
1. What is Diffie-Hellman key exchange?
It lets two parties derive matching secret material. Public values travel across an untrusted network. Private exponents remain known only to their owners.
2. What are p and g?
The value p defines the finite field. The value g generates elements inside that field. Both parameters are normally public and standardised.
3. What is a private key?
A private key is a secret exponent. It creates the related public key. It must remain unpredictable and confidential.
4. What is a public key?
A public key is modular exponentiation output. Other participants may receive it openly. Validation prevents trivial or subgroup values.
5. Why do both shared secrets match?
Both calculations reduce to the same exponent product. Modular arithmetic preserves that shared result. Neither side transmits the secret directly.
6. Is Diffie-Hellman encryption?
Diffie-Hellman is a key-agreement method. It does not encrypt application data itself. Derived keys can later support authenticated encryption.
7. Can it stop man-in-the-middle attacks?
Unauthenticated Diffie-Hellman cannot stop active substitution. Certificates or signatures authenticate exchanged public values. Protocol design must bind identities securely.
8. What key size should be used?
Production requirements depend on current standards and policies. Small classroom groups are never production ready. Use approved libraries and organisation guidance.
9. What differs between DH and ECDH?
Classic DH works in multiplicative finite fields. ECDH uses elliptic-curve point multiplication. ECDH often achieves smaller keys for comparable security.