What is a digital signature, and how does it prove data wasn't changed?
Quick Answer
A digital signature lets someone prove they own a private key, and prove that a specific piece of data has not been altered. The signer hashes the data, then encrypts that hash with their private key. Anyone can verify it using the signer's public key: they hash the data themselves and check it matches the decrypted signature. TLS certificates are signed this way, so browsers can trust that a certificate wasn't forged.
Detailed Answer
A digital signature proves two things at once:
- Authenticity — the data really came from the claimed sender.
- Integrity — the data was not changed after it was signed.
Signing (done by the owner of the private key):
data --[hash]--> digest --[encrypt digest with private key]--> signature
Verifying (done by anyone with the public key):
received data --[hash]--> digest A
signature --[decrypt with public key]--> digest B
if digest A == digest B: signature is valid
If even one byte of the data changes, the hash the verifier computes (digest A) will not match digest B, and verification fails. Since only the real owner of the private key could have produced a valid signature in the first place, a passing check also proves who signed it.
This is exactly how TLS certificates work. A Certificate Authority (CA) signs a website's certificate with the CA's own private key. Your browser already has the CA's public key built in, so it can verify the signature and trust that the certificate is genuine and untampered. The next topic covers certificates and this trust chain in more detail.