A digital signature is a short block of data, made with a private key, that lets anyone holding the matching public key confirm who signed a message and that it hasn't changed by even one bit since. Change the message after signing and verification fails; sign with a different key and verification fails too.
NIST's Digital Signature Standard (FIPS 186-5) names three uses: detecting unauthorised modification of data, authenticating the identity of the signer, and non-repudiation, meaning the signer can't plausibly deny having signed. You rely on all three every time your computer installs a signed update or your browser accepts an HTTPS certificate.
How a digital signature works
Signing uses a key pair (see public-key cryptography explained for how key pairs work). The private key stays with the signer; the public key is published.
- Hash the message. The signing process usually starts by running the message through a hash function such as SHA-256, producing a short fixed-length fingerprint. FIPS 186-5 calls this condensed version the message digest. Any change to the message gives a completely different digest.
- Sign the digest with the private key. The signature algorithm combines the digest with the private key to produce the signature.
- Send the message and the signature. The message itself isn't hidden. Signing is about proof, not secrecy.
- Verify with the public key. The recipient hashes the message they received and runs the verification algorithm with the signer's public key, the digest and the signature. It returns valid or invalid, nothing in between.
Only the private key can produce a signature that the public key accepts, and working out the private key from the public key is computationally infeasible with current algorithms and key sizes. That asymmetry is the whole point: anyone can check, only one party can sign.
Try it: sign and verify a file with OpenSSL
These commands work with OpenSSL 3.x on Linux, macOS, and Windows (Git Bash includes it). They were run with OpenSSL 3.2.1 in a scratch folder. First create an Ed25519 key pair:
openssl genpkey -algorithm ed25519 -out private.pem
openssl pkey -in private.pem -pubout -out public.pem
Sign a message and verify it:
printf 'Pay Alex 100 EUR\n' > message.txt
openssl pkeyutl -sign -inkey private.pem -rawin -in message.txt -out message.sig
openssl pkeyutl -verify -pubin -inkey public.pem -rawin -in message.txt -sigfile message.sig
Output:
Signature Verified Successfully
Now change one character of the message and verify again with the same signature:
printf 'Pay Alex 900 EUR\n' > message.txt
openssl pkeyutl -verify -pubin -inkey public.pem -rawin -in message.txt -sigfile message.sig
Output (exit code 1):
Signature Verification Failure
The signature file is 64 bytes, which matches RFC 8032: Ed25519 signatures are 64 octets and public keys are 32 octets. The same test with a 3072-bit RSA key (openssl dgst -sha256 -sign rsa.pem -out m2.sig m2.txt) produced a 384-byte signature and verified with Verified OK. RSA signatures are as long as the key: 3072 bits is 384 bytes.
Signing with an SSH key
If you already have an SSH key (see generate an SSH key with ed25519), OpenSSH can sign files with it. Git can also sign commits and tags with an SSH key when gpg.format is set to ssh (the other options are openpgp, the default, and x509).
ssh-keygen -Y sign -f ~/.ssh/id_ed25519 -n file notes.txt
That writes notes.txt.sig, which starts with -----BEGIN SSH SIGNATURE-----. To verify, list trusted signers in a file, one per line as email key:
echo "[email protected] $(cat ~/.ssh/id_ed25519.pub)" > allowed_signers
ssh-keygen -Y verify -f allowed_signers -I [email protected] -n file -s notes.txt.sig < notes.txt
Example output on success, and after editing the file:
Good "file" signature for [email protected] with ED25519 key SHA256:UjELGLWXW8alLyJbm8Jn/x4ft7eF+uoGdmWyIUdINDE
Signature verification failed: incorrect signature
Could not verify signature.
The -n file part is a namespace, which the manual says is "used to prevent signature confusion across different domains of use": a signature made in the file namespace is not accepted where another namespace, such as email, is expected. A zero exit status means verification succeeded.
Which signature algorithms are used
| Algorithm | Specified in | Signature size | Notes |
|---|---|---|---|
| RSA | RFC 8017 (PKCS #1), approved in FIPS 186-5 | Same as key size (384 bytes for 3072-bit) | Oldest and most widely supported |
| ECDSA | FIPS 186-5 | 71 bytes in our P-256 test (DER-encoded; varies by a byte or two) | Common in TLS certificates; deterministic variant in RFC 6979 also approved |
| EdDSA (Ed25519) | RFC 8032, approved in FIPS 186-5 | 64 bytes | Deterministic: no random number needed per signature; about 128-bit security |
| DSA | FIPS 186-4 (older) | n/a | No longer specified in FIPS 186-5; only for verifying old signatures |
| ML-DSA | FIPS 204 (August 2024) | 2,420 to 4,627 bytes | Post-quantum: believed secure against large quantum computers |
EdDSA's determinism matters in practice. RFC 8032 states that EdDSA signatures are deterministic, so signing does not depend on a good random number generator at signing time. NIST published ML-DSA in FIPS 204 because a large quantum computer would break RSA, ECDSA and EdDSA; FIPS 204 describes ML-DSA as "believed to be secure, even against adversaries in possession of a large-scale quantum computer."
Where you meet digital signatures every day
- HTTPS. Certificates are signed by a certificate authority, and in TLS 1.3 the server sends a CertificateVerify message: "a signature over the entire handshake using the private key corresponding to the public key in the Certificate message".
- Software and releases. Signed packages, installers and release files are checked against the publisher's public key before you trust them.
- Git. Signed commits and tags let others verify who created them, using OpenPGP, X.509 or SSH keys.
- Passkeys. Signing in with a passkey works by your device signing a challenge from the website with a private key; see passkeys explained.
Signature vs hash vs HMAC
A plain hash, such as the SHA-256 checksum published next to a download, detects accidental corruption, but anyone who can change the file can also change the published hash. You can compute one with the larely checksum tool to compare against a published value. An HMAC adds a secret key, so only key holders can produce a valid tag, but everyone who can verify can also create tags, which suits two systems that already share a secret; the HMAC generator shows how it works. A digital signature is the only one of the three that lets the whole world verify while only one party can sign.
If verification fails
A failed check means one of three things: the data changed (even a line-ending conversion from LF to CRLF counts), the signature belongs to a different key than the one you're verifying with, or the signature file itself is damaged. Check that you are hashing the exact bytes that were signed, that the public key really belongs to the signer, and that the signature and data files were transferred in binary mode. Never "fix" a failure by skipping verification; a mismatch is exactly what the signature exists to catch.
Frequently asked questions
- What is the difference between a digital signature and an electronic signature?
- An electronic signature is any electronic sign of agreement, such as a typed name, a drawn signature image or a ticked box. A digital signature is a specific cryptographic technique that proves which key signed the data and that the data hasn't changed since. Many document-signing services use digital signatures underneath, but a pasted image of your handwriting is not one.
- Is a digital signature the same as encryption?
- No. Signing does not hide anything: the signed message is usually sent in plain form alongside the signature. Encryption provides confidentiality using the recipient's public key; a signature provides integrity and proof of origin using the signer's private key. Systems often do both.
- Can a digital signature be forged?
- Not without the private key, with current algorithms and key sizes. The practical risks are elsewhere: a stolen private key, a public key you were tricked into trusting, or software that skips verification. Protect the private key and get the public key from a source you trust.
- What is the difference between a digital signature and an HMAC?
- An HMAC uses one shared secret key for both creating and checking the tag, so anyone who can verify can also forge. A digital signature uses a private key to sign and a public key to verify, so anyone can check it but only the key holder can create it. That is why signatures, unlike HMACs, can prove origin to a third party.
Sources
- NIST FIPS 186-5: Digital Signature Standard (DSS)
- RFC 8032: Edwards-Curve Digital Signature Algorithm (EdDSA)
- NIST FIPS 204: Module-Lattice-Based Digital Signature Standard (ML-DSA)
- RFC 8017: PKCS #1, RSA Cryptography Specifications Version 2.2
- OpenSSH manual: ssh-keygen(1) (signing with -Y sign)
- Git documentation: git-config (gpg.format)
- RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3