How Digital Signatures Work
Digital signatures combine hashing, private-key signing, and public verification.
A digital signature proves two separate things: who could have created a message, and whether the signed content changed afterwards. It does not work by encrypting the whole document with the sender's private key. That common shortcut misses the real mechanism.
The real flow has three parts: hashing, signing, and verification.
1. Hash the document
The sender first runs the document through a cryptographic hash function such as SHA-256. A hash turns any input into a fixed-length digest. Change one bit in the document and the digest changes completely. This digest is much smaller than the original file, which is why signatures are usually applied to the hash rather than to the whole document.
2. Sign the hash with a private key
The signer owns a private key and shares the matching public key. Using the private key, the signer computes a digital signature over the hash. The exact maths depends on the algorithm, such as RSA-PSS or ECDSA, but the point is the same: only someone with the private key should be able to create a valid signature.
The signed package usually includes the original document, the signature, and often a certificate that binds the public key to a named identity.
3. Verify with the public key
The recipient performs two checks. First, they hash the received document themselves. Second, they use the public key to verify the signature. If the signature is valid and the newly calculated hash matches the signed hash, the content has not changed since it was signed.
That gives integrity. If the recipient also trusts that the public key really belongs to the claimed signer, it gives authenticity as well.
Why certificates matter
A public key by itself does not tell you whose key it is. A certificate authority, company PKI, or another trust mechanism is what ties the key to a person, service, or organisation. Without that binding, a signature proves only that the same unknown key signed the document, not that "this was definitely Maria from finance".
This is why code-signing certificates, PDF signing certificates, and TLS certificates matter. Trust is not only about the algorithm. It is also about the key distribution system around the algorithm.
Digital signatures are not encryption
Encryption hides the contents from unauthorised readers. Digital signatures do something else. They leave the message readable, but make tampering detectable. Many real systems use both together: encrypt for confidentiality, sign for authenticity and integrity.
Operational details that matter in practice
Real systems have messy edges. Canonicalisation matters, because two files that look the same to a human may hash differently if whitespace or encoding changes. Key compromise matters, because a stolen private key lets an attacker create valid signatures until the key is revoked. Time matters too. A signature may have been valid when created but no longer trustworthy years later unless there is a trusted timestamp showing when it was made.
So the practical mental model is this: a digital signature is a mathematically verifiable stamp created with a private key and checked with a public key. The maths protects the content. The surrounding trust system protects the identity claim.