Skip to content
100% local

Diffie-Hellman key exchange

Compute a Diffie-Hellman shared secret from your private key and the other party's public value, entirely in your browser.

Input
Output

Diffie-Hellman key exchange

This calculator walks through one side of a Diffie-Hellman key exchange: given your private key and the public value you received from the other party, it derives your own public key and the shared secret both sides end up with. It's built for developers checking a handshake against a reference implementation, and for anyone learning how the protocol turns two private numbers into one shared one without either party ever sending it across the wire.

Pick a key size to choose the built-in prime (p) and generator (g = 2) the exchange runs over — 2048-bit is the safe default, 1024-bit is kept for working with legacy systems, and 512-bit is for following the arithmetic by hand, not for anything real. The public key format option reads the value you paste as decimal digits, hexadecimal or Base64, however it arrived; the output format controls how your own public key and the shared secret are rendered. An optional expected-value field checks the computed secret against one you already have, so you can confirm two implementations agree.

The tool rejects a private key that isn't a positive whole number and a public value of 0, 1 or p−1 — those degenerate values would produce a predictable shared secret no matter what private key is used, so a real implementation should reject them too. Note that classic Diffie-Hellman has no salt or iteration count; those belong to password-based key derivation, not to this exchange.

Everything runs locally in your browser using JavaScript's native BigInt arithmetic — your private key and the computed secret are never sent anywhere. Copy the result, download it as a .txt file, or send it back into the input to run another calculation.

FAQ

Can I use my own prime and generator?
No — each key size uses a fixed, verified safe prime built into the tool, with generator 2. If you need to check a handshake against a specific p and g, use a tool that accepts them directly.
Why does it reject public values of 0, 1 or p−1?
Those values collapse the shared secret to something predictable regardless of the private key involved — a small-subgroup weakness real implementations guard against too, so this tool refuses them rather than silently computing a meaningless result.
Does the key size need to match the other party's?
Yes. Both sides must compute over the same prime and generator, which here means picking the same key size — a public value generated under a different key size will fail the range check or produce a different secret.
Does this tool use a salt or an iteration count?
No. Classic Diffie-Hellman doesn't use either — those are features of password-based key derivation functions like PBKDF2, not of this exchange.
Is my private key uploaded anywhere?
No. The private key field is masked and never stored — the whole calculation runs in your browser and nothing leaves your device.