HomeGuides › Public-key cryptography

How public-key cryptography actually works

Two keys, mathematically linked. One you publish, one you keep. Here it is done with real keys rather than an analogy.

Public-key cryptography solves a problem that looks impossible: communicating securely with someone you have never met and share no secret with. The trick is that the two keys are linked so that what one does, only the other undoes — and having one does not let you work out the other.

What the tool does

It generates a genuine ECDSA key pair, signs a message you type, and verifies the result — with each step shown. Then it breaks the signature in two ways, which is the part worth staying for.

The two ways it fails

Change the message. Alter one character and verification fails. The signature covers the exact bytes, so it commits the signer to that message and no other. This is why a signature proves integrity as well as origin.

Verify with the wrong key. Check the signature against somebody else's public key and it fails. The signature only verifies against the public key partnered with the private key that made it.

Both failures are the mechanism doing its job, and seeing them is more instructive than any number of successful verifications.

The part the mathematics cannot do

A valid signature says: the holder of the private key matching this public key signed this exact content. It does not say who that holder is. Binding a key to a person is a human problem, solved by meeting them, by a certificate authority vouching for it, or by a key published somewhere you already have reason to trust.

This is the gap certificates exist to fill, and where most real-world failures happen — not in the cryptography, but in someone accepting a key from the same untrusted place as the thing it was meant to authenticate.

Signing and encrypting are different

Signing uses the private key and is checked with the public key; it proves origin. Encrypting to someone uses their public key so that only their private key can open it; it provides confidentiality. Neither implies the other, and a signed message is completely readable by anybody.

Frequently asked questions

Are these real keys or a simulation?

Real ones, generated by your browser's own cryptographic implementation. The signatures verify against any standards-compliant implementation.

If the public key is public, why is this secure?

Because deriving the private key from the public one requires solving a problem believed to be computationally infeasible. Publishing the public key is intended and safe.

Can I encrypt with a signing key?

Not with these. ECDSA and Ed25519 keys are for signatures only. Encryption uses different algorithms, and reusing a key across purposes is a bad practice even where it is technically possible.

Open the visualizer →