Security

Diffie-Hellman key exchange explained

How Diffie-Hellman key exchange lets two sides agree a secret key over a public network without ever sending it, with a worked example and forward secrecy.

  • 6 min read
  • 5 questions
  • +35 XP
Transcript

Diffie Hellman, explained by cats. Kitty wants to share a secret with another cat. But the internet is public. Other cats are watching. So how do two cats agree on a secret without ever sending it? Diffie–Hellman. makes that possible.

This is how it works. First, both cats agree on something public. like A bowl of tuna. Other cats can see this, but That’s fine. Next, each cat adds a secret seasoning. to the tuna bowl. It's Private. No cat must see this.

They mix and then swap their bowls. Snooping cats see tuna moving. But they never see the seasoning. And they can’t reverse it. Now the magic. Each cat adds their secret seasoning again to the other bowl. Because of how the mixing works, both bowls end up identical.

No secret was sent. It was discovered independently. That bowl becomes the shared key. Now messages can be encrypted. The key was never transmitted. It was discovered through clever math. Diffie–Hellman isn’t encryption. It just creates the key.