← Archive
// Archive

Secure communication

Two terminals that agree on keys and then chat with every message encrypted.

Pythoncryptography

A Python project that lets two terminals talk to each other securely. They first generate and exchange keys to set up a secure connection, and from then on every message is encrypted before it’s sent and decrypted when it arrives. The two sides can then chat without anyone in between being able to read it.

Under the hood, each side first proves who it is with an ECDSA signature. Then they agree on a shared key with an X25519 key exchange and HKDF, without the key ever going over the network. Every message gets a Poly1305 authentication code and is encrypted together with it using Fernet.

The demo below runs the same steps between a server and a client in your browser, using its built-in cryptography. The middle column shows what someone listening in would see. Let Eve change a message on the way, and the receiver throws it away.

Watch it work

The server and the client below run the app's protocol for real, with the browser's own cryptography. Step through the handshake, then chat.

Server

    The wire what an eavesdropper sees

      Client