Skip to content
ufraan
← Back

Diffie-Hell

Diffie-Hellman key exchange implemented from scratch in Go, with the shared secret turned into an AES-256-GCM encryption key.

GoCryptographyKey Exchange
Aug 2026GitHub

diffie-hell is a from-scratch implementation of the Diffie-Hellman key exchange in Go. Alice and Bob each generate a private key with crypto/rand, derive their public keys through modular exponentiation on math/big integers, exchange them, and then independently compute the same shared secret - the core idea behind how TLS establishes trust over an untrusted network.

From there, the shared secret gets hashed with SHA-256 into a 32-byte AES-256 key, and the program encrypts and decrypts a message using AES-GCM to prove the negotiated secret is actually usable for symmetric encryption. Small, but it covers the full path from handshake to ciphertext end to end.