Digital Signatures Explained
Learn how private keys sign and public keys verify, what a valid signature proves, where you rely on it, and how to try it yourself.
Key takeaways
- A signature is created with a private key and verified with the matching public key.
- A valid signature shows the data is unchanged and that the holder of the private key produced it.
- Verification means little unless you have good reason to believe the public key belongs to who you think it does.
- Signing does not hide content; encryption is a separate step.
- A typed name or scanned signature image is not a cryptographic digital signature.
A digital signature is a value computed from a piece of data and a private key. Anyone with the matching public key can check it. If the check passes, the data hasn't changed since signing and the signer had access to that private key.
Signatures quietly protect software updates, website certificates, secure logins and many electronic documents. Understanding what they prove, and what they don't, helps you interpret the green checkmarks and warnings you see.
Signing and verifying
The process usually runs like this. The signer's software computes a hash of the data, a fixed-length fingerprint. It then runs a signing algorithm on that fingerprint with the private key, producing the signature. The data and signature travel together or separately.
The verifier hashes the data they received and runs the verification algorithm with the signature and public key. The answer is simply valid or invalid. Altering a single character of the data changes the hash, so verification fails.
Schemes differ internally. Some textbooks call signing "encrypting the hash with the private key." That is a loose description of one form of RSA and doesn't fit elliptic-curve or newer methods, so think of signing and verifying as their own operations.
Hashing itself is covered in hashing vs. encryption vs. encoding.
A hypothetical example
Say a small company sends a supplier a purchase order as a signed file. The company's purchasing officer has a private key, and the supplier already holds the matching public key, confirmed when the two firms first set up the arrangement.
The supplier's software verifies the order and reports it as valid. Now suppose someone changes the quantity from 10 to 100 along the way. The fingerprint of the received file no longer matches what was signed, and verification fails. Suppose instead the attacker writes a fresh order and signs it with their own key. The mathematics works out for that key, but it isn't the key the supplier has on record, so it fails too.
Two weaknesses remain. If the attacker steals the officer's private key, forged orders will verify, until the key is revoked. And if the attacker talks the supplier into accepting a "new key" by email, every later check passes against the wrong identity. Both attacks go around the math, which is why key custody and key changes deserve as much care as the algorithm.
What a valid signature tells you
| Property | Meaning | Limit |
|---|---|---|
| Integrity | The data matches what was signed | Says nothing about whether the content is true |
| Authenticity | Someone with the private key signed it | Depends on trusting the public key's owner |
| Non-repudiation | The signer finds it hard to deny signing | A stolen key or legal context can complicate this |
| Confidentiality | Not provided | Encrypt separately if secrecy matters |
| Timing | Not provided by the signature alone | A trusted timestamp is needed |
A signed file can still be harmful. A criminal can sign malware with their own key, or with a stolen one. The question is always: signed by whom, and do I trust them for this purpose?
Signatures compared with shared-key checks
A related tool, the message authentication code (such as HMAC), also detects tampering. It uses one secret that both sides hold. That is fast and works well between two systems that already trust each other, for instance a service notifying your server of an event.
Its limit is that either side could have produced the code, so it can't show a third party who wrote a message. A digital signature uses a private key only one side holds, while everyone else gets the public key. That is why public distribution, such as software releases read by millions, calls for signatures: you can hand out the means of checking without handing out the means of forging.
Linking keys to identities
A public key is just a number. Something has to tie it to a person or organization.
- Certificate authorities issue certificates stating that a key belongs to a domain or organization, and sign those certificates themselves. Your operating system or browser ships with a list of trusted root authorities. See certificates and certificate authorities.
- Direct exchange: you receive a key fingerprint from the person through a channel you trust.
- Pinned or preinstalled keys: a device ships with the maker's public key and accepts only updates signed by it.
- Web of trust: used in some PGP communities, where people vouch for each other's keys.
Where you rely on signatures
Software and updates. Operating systems and app stores check signatures before installing. This stops a tampered download from passing as the original. When your system warns about an unknown publisher, the signature is missing or not trusted.
HTTPS. Certificates are signed documents, and the server also signs part of the handshake. HTTPS and TLS puts it together.
DNS. DNSSEC signs records so resolvers can detect forgery.
Email. DKIM lets a sending domain sign messages so receivers can check they weren't altered and that the domain takes responsibility for them. It doesn't verify that the content is honest.
Passkeys and security keys. At login, your device signs a fresh challenge from the site. The private key never leaves it, and the signature is bound to the site's identity, which is why passkeys resist phishing.
Code repositories. Developers can sign commits and release tags.
Documents. PDF readers can validate certificate-based signatures and show whether the file changed afterward.
Digital signatures and e-signatures
These terms overlap but differ. An electronic signature is a legal concept: any electronic mark or process showing intent to agree, which might be a typed name, a drawn squiggle or a click. A digital signature is the cryptographic technique. Some e-signature services use digital signatures behind the scenes to seal the finished document and record an audit trail.
Legal weight depends on the jurisdiction and document type. Laws such as the US ESIGN Act and the European eIDAS framework recognize electronic signatures in many situations, with some exceptions and, in places, higher tiers for qualified signatures. Check the rules that apply before relying on one for something important.
Common algorithms
- RSA, usually with the PSS or older PKCS #1 v1.5 padding.
- ECDSA, an elliptic-curve method widely used in certificates. It is sensitive to poor randomness in the signing step.
- EdDSA, including Ed25519 (RFC 8032), with small keys and signatures and deterministic signing.
- ML-DSA and SLH-DSA, quantum-resistant signature standards published by NIST as FIPS 204 and FIPS 205. Their signatures are considerably larger, discussed in post-quantum cryptography.
NIST's digital signature standard is FIPS 186. Choose what your tools and partners support and follow current guidance on key sizes.
Try it with OpenSSL
On a system with OpenSSL installed, you can sign and verify a file. Create a key pair:
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out private.pem
openssl pkey -in private.pem -pubout -out public.pem Sign a file with the private key, then verify with the public one:
openssl dgst -sha256 -sign private.pem -out report.sig report.txt
openssl dgst -sha256 -verify public.pem -signature report.sig report.txt The second command reports that verification succeeded. Now add a space to report.txt and run it again. It fails, which is the whole point.
Treat private.pem as a secret. This example creates an unprotected key for learning; for real use, protect keys with a passphrase or keep them in hardware, such as a security key or managed key service.
When verification fails or warns
Expiry needs nuance. A document signed while a certificate was valid can remain verifiable later if a trusted timestamp records when the signing occurred. Without one, software may be unable to tell.
Protecting signing keys
Whoever holds a private key can sign as you. Good practice includes storing keys in hardware that won't export them, limiting who can request a signature, keeping signing machines separate from everyday browsing, logging every use, setting expiry dates and knowing how to revoke a key. Organizations that publish software should treat their signing keys as among their most sensitive assets.
For individuals the basics are simpler: use a passphrase, back up keys securely if losing them would matter and revoke any key you think was copied.
Revocation and what happens after a theft
Certificates and many key systems let an owner withdraw trust before the expiry date. Certificate authorities publish revocation information, and software vendors can block a signing certificate known to be abused. The checks aren't perfect: some clients cache old answers, some skip the check when the lookup fails and offline devices may not hear the news for a long time.
If a key of yours is exposed, revoke it, generate a new one, announce the change through a channel the thief doesn't control and review anything signed during the window of doubt. Having that plan written down beforehand saves hours at the worst moment. Short certificate lifetimes help too, since a stolen credential that expires soon does less damage.
Common questions
Can a signature be copied onto another document?
No. A signature is computed from the specific data, so attaching it to different content makes verification fail.
Does signing encrypt my file?
No. A signed file is normally still readable by anyone. To get both properties, sign and encrypt using a protocol designed to combine them.