Skip to content
Velloreth
Cybersecurity 5 min read

Digital Signatures Explained: Signing and Verifying

A signature proves who sent a message and that it was not changed. Learn the keys, the hash, the verification and the common mistakes.

By

What a signature proves

Integrity. The message was not changed.

Origin. The holder of the private key signed it.

What it does not prove:

  • Confidentiality — the message is readable
  • The time — unless a timestamp is included
  • That the signer is trustworthy — only that they signed

How it works

1. Hash the message.

digest = SHA-256(message)

2. Sign the digest with the private key.

signature = sign(digest, privateKey)

3. Send the message and the signature.

4. Verify.

digest = SHA-256(message)
valid = verify(signature, digest, publicKey)

The message is hashed first because a signature operation is slow and a digest is a fixed size.

The algorithms

AlgorithmNotes
RSA-PSSwidely supported, large keys
ECDSAsmall keys, fast
Ed25519modern, fast, small, the default choice
DSAlegacy, avoid

Ed25519 is the modern default for a new system.

The hash is SHA-256 or SHA-3. MD5 and SHA-1 are broken for this purpose.

Signature versus MAC

SignatureMAC
Keya key paira shared secret
Who can verifyanyone with the public keyanyone with the secret
Who can signthe private key holderanyone with the secret
Usea public verificationa shared-secret context

A signature is the right choice when the verifier is not trusted to sign.

A MAC is faster and is the right choice when both sides share a secret.

Where it is used

A software release. The maintainer signs the artifact, and the user verifies it.

A JWT. The issuer signs the token, and the resource server verifies it.

A TLS certificate. The certificate authority signs the certificate.

A git commit. The developer signs the commit, and the host verifies it.

A package. The registry signs the package metadata.

An email. DKIM signs the message.

An API request. The client signs the request, and the server verifies it.

The verification

Verify the signature and the key.

The key must be trusted. A valid signature for an attacker’s key proves nothing.

The mechanisms:

MechanismHow the key is trusted
A certificate chaina root authority
A pinned keya known value
A key servera directory, with a trust decision
A published fingerprinta value compared out of band

A certificate chain is the common case for TLS.

A pinned key is the common case for a package or a release.

The fingerprint is the value to compare, and it is short enough to read aloud.

The timestamp

A signature does not prove when it was made.

A timestamp authority signs the digest and the time, which proves the message existed at that time.

A counter-signature is the same idea.

Why it matters: a signature made after a key was revoked is still valid without a timestamp.

The traps

Verifying the signature without the key. The most common mistake.

A weak hash. MD5 or SHA-1.

A nonce reuse in ECDSA. Reusing the random value leaks the private key.

A signature over the wrong data. Signing a hash of a different representation, such as a JSON with a different key order.

A canonicalisation problem. Two representations of the same data produce different signatures.

A signature that is not checked. A library that returns a result that is ignored.

A key that is not rotated. A compromised key stays valid.

A signature over a message that is then modified. The signature covers the original.

Signing a release

A release signature is the case where the key verification matters most, because the user is trusting a binary that will run with their privileges. The maintainer signs the artifact with a private key, publishes the signature and the public key, and the user verifies both. The second practice is to publish the fingerprint in a place that is hard to change, such as a website and a repository, so a tampered key is visible. The third is to sign the checksum file rather than each artifact, which is one signature for a release. The fourth is to keep the signing key offline, because a key on a build server is a key that a compromise of the build server exposes. The fifth is to document the verification command, because a signature that the user does not know how to check provides no protection.

Common mistakes

No key verification. A valid signature for the wrong key.

A weak hash. A collision.

A nonce reuse. A leaked private key.

A canonicalisation mismatch. A verification failure that is hard to debug.

An unchecked result. The signature is computed and ignored.

No timestamp. The time is not proven.

A key that is not rotated. A long-lived compromise.

A signature used for confidentiality. The message is readable.

A hand-rolled scheme. A subtle flaw.

A quotable summary

A digital signature is computed from a message and a private key and verified with the matching public key, and it proves integrity and origin but not confidentiality or the time. The message is hashed first and the digest is signed, Ed25519 is the modern default, and the verifier must check the key as well as the signature, because a valid signature for an attacker’s key proves nothing.

For the related topics, see encryption-at-rest-vs-transit and zero-trust-for-small-teams. For the broader context, password-storage-best-practices and oauth2-explained.

Frequently asked questions

What is a digital signature?
It is a value computed from a message and a private key that anyone with the matching public key can verify. It proves that the holder of the private key signed the message and that the message was not changed. It does not hide the message, which is what encryption does.
How does signing work?
The message is hashed to a fixed-size digest, and the digest is signed with the private key. The signature is sent with the message. The verifier hashes the message again, and uses the public key to check that the signature matches the digest.
What is the difference between a signature and a MAC?
A MAC uses a shared secret, so anyone who can verify can also sign. A signature uses a key pair, so the verifier can check without being able to sign. A signature is the right choice when the verifier is not trusted to sign.
Does a signature encrypt the message?
No. A signature proves the origin and the integrity, and the message is still readable. To hide the message, encrypt it as well. A common pattern is to sign and then encrypt, or to encrypt and then sign, and the order matters for the security property.
What is a signature used for?
A software release, a JWT, a TLS certificate, a git commit, a package, an email, and an API request. In each case the goal is to prove that the content came from the expected source and was not modified.
What is the most common mistake?
Verifying the signature without verifying the key. A signature that is valid for an attacker's key proves nothing. The verifier must check that the public key belongs to the expected signer, which is what a certificate chain or a pinned key provides.