Digital signatures
A digital signature binds a message to a private key. Anyone with the public key can verify it — instantly catching any modification.
In this lesson
- Describe the sign and verify operations
- Explain what a signature does and does not prove
- Verify a signed file from the terminal
Sign with the private, verify with the public
To sign, the signer hashes the message and encrypts that hash with their private key. To verify, anyone hashes the message again, decrypts the signature with the public key, and compares. Match → authentic and unmodified.
Example · Code signing in practice
When you install a signed macOS app, the OS checks the developer's signature against a trusted certificate chain. Malware authors cannot re-sign tampered code without the developer's private key — so the OS refuses to run it.
The same mechanism guards Windows drivers, npm packages and firmware.
openssl genpkey -algorithm ed25519 -out key.pem\nopenssl pkey -in key.pem -pubout -out key.pub\n\nopenssl pkeyutl -sign -inkey key.pem -rawin -in message.txt -out sig.bin\nopenssl pkeyutl -verify -pubin -inkey key.pub -rawin -in message.txt -in sig.bin\n# Verified OK
Signatures prove three things at once:
- Authenticity — it came from the holder of the private key.
- Integrity — not one byte changed since signing.
- Non-repudiation — the signer cannot later deny it (they alone hold the key).
A signature is not encryption
Signing does not hide the message. Everyone who has the file can read it — they can only verify who produced it. If you also need secrecy, encrypt separately.
Sign, verify, tamper
Sign a message in the lab, verify it, then alter one character and verify again.
How long does verification take?
Milliseconds — verification is much cheaper than signing, which is why signatures scale to billions of certificates.
What if my private key leaks?
You revoke the certificate and re-issue. Signature schemes have no "undo": anyone can forge signatures for messages signed while the key was valid.