A digital signature is a cryptographic mechanism that verifies the authenticity and integrity of a digital document, essentially acting as a tamper-proof seal.

Let’s see this in action with a simplified example. Imagine Alice wants to send a contract to Bob, and she wants Bob to be sure it’s really from her and hasn’t been altered.

First, Alice needs a private key and a public key. These are mathematically linked pairs. Her private key is kept secret, while her public key is shared widely.

Alice takes the contract (let’s call it contract.txt) and uses a hashing algorithm, like SHA-256, to create a unique, fixed-size "fingerprint" of the document. This is called a hash.

echo -n "I, Alice, agree to sell my car to Bob for $5000." > contract.txt
openssl dgst -sha256 contract.txt
# Output: SHA256(contract.txt)=a1b2c3d4e5f6... (a long hex string)

This hash is crucial. Even a tiny change to contract.txt will result in a completely different hash.

Next, Alice "signs" this hash using her private key. This process encrypts the hash with her private key. The result is the digital signature.

# Assuming Alice has her private key in alice_private.pem
openssl pkeyutl -sign -inkey alice_private.pem -in contract_hash.bin -out contract.sig

Now, Alice sends both the original contract.txt and the contract.sig file to Bob.

Bob receives both files. To verify the signature, he first calculates the hash of the contract.txt he received, using the exact same hashing algorithm Alice used.

openssl dgst -sha256 contract.txt
# Bob calculates this hash on his end

Then, Bob uses Alice’s public key to "decrypt" the contract.sig file. This reveals the original hash that Alice signed.

# Assuming Bob has Alice's public key in alice_public.pem
openssl pkeyutl -verify -pubin -inkey alice_public.pem -in contract_hash.bin -sigfile contract.sig

If the hash Bob calculated from the received document matches the hash he recovered from the signature, then two things are confirmed:

  1. Authenticity: Only Alice, with her private key, could have created a signature that decrypts correctly with her public key.
  2. Integrity: The document hasn’t been altered since it was signed, because the hash would have changed.

The core problem digital signatures solve is establishing trust in a digital environment where documents can be easily copied, modified, and forwarded. Without them, you’d have no reliable way to confirm who sent a document or if it’s the exact version they intended.

Internally, this relies on asymmetric cryptography (public-key cryptography). The private key is used for signing (encrypting the hash), and the corresponding public key is used for verification (decrypting the hash). The hashing algorithm ensures that any modification to the document, no matter how small, will produce a fundamentally different hash, thus invalidating the signature. The specific algorithms and key lengths used (e.g., RSA with 2048-bit keys, SHA-256) dictate the security strength of the signature.

A common point of confusion is the difference between signing the document and signing the hash of the document. Signing the entire document would be computationally infeasible for large files. Instead, signing the fixed-size hash is efficient and provides the same integrity guarantee. The signature is essentially a statement from the signer, cryptographically bound to the document’s content at the time of signing, and verifiable by anyone who possesses the signer’s public key.

The next step in building trust is understanding certificate authorities and how public keys themselves are reliably distributed and validated.

Want structured learning?

Take the full Cryptography course →