Hashing, Digital Signatures and Public Key Infrastructure
Hash functions, digital signatures and certificates let parties verify integrity and identity at scale. This lesson explains how they work together in a public key infrastructure.
Learning outcomes
After completing this lesson, you will be able to:
- Explain hash functions, MACs and digital signatures.
- Describe how PKI issues, validates and revokes certificates.
Hash functions and MACs
A hash function produces a fixed-length digest from input of any length. A secure hash is one-way (the input cannot be derived from the digest) and collision-resistant (it is infeasible to find two inputs with the same digest). The SHA-2 family (SHA-256, SHA-384, SHA-512) and SHA-3 are current standards; MD5 and SHA-1 are broken for collision resistance. The birthday attack means that collisions are found after about 2n/2 attempts for an n-bit hash.
The birthday attack explains why hash lengths are chosen as they are. In a room of only 23 people, there is a better than even chance that two share a birthday, because the number of possible pairs grows much faster than the number of people. In the same way, an attacker looking for any two inputs with the same digest needs about 2n/2 attempts rather than 2n, so a 256-bit hash offers about 128 bits of collision resistance. Collisions matter because a signature on one document is equally valid for any other document with the same digest.
A hash alone detects accidental change but not deliberate tampering, because an attacker can recompute it. A message authentication code such as HMAC combines a hash with a secret key, so only key holders can produce a valid code, giving integrity and authenticity between them. For stored passwords, slow, salted functions designed for the purpose, such as bcrypt, scrypt, PBKDF2 or Argon2, are used instead of plain hashes.
Hashes, MACs and passwords
Verifying a downloaded installer
A software vendor publishes the SHA-256 digest of an installer on its website, and an administrator downloads the installer from a mirror site. How does the administrator check it, and what are the limits of the check?
The administrator computes the digest locally and compares it with the published value; a single changed byte in the file would produce a completely different digest.
The comparison is only meaningful if the published digest itself is trustworthy, because an attacker who can replace the installer on the mirror and the digest on the same page can simply publish a matching pair. That limitation is what MACs and digital signatures address.
Digital signatures
To create a digital signature, the signer hashes the message and transforms the hash with their private key. The verifier hashes the received message, checks the signature with the signer's public key and compares the results.
-
Hash
The sender computes a hash of the message.
-
Sign
The sender signs the hash with their private key.
-
Send
The message and signature are sent together.
-
Verify
The recipient hashes the message and checks the signature with the sender's public key.
-
Compare
A match proves integrity and origin; a mismatch means tampering or a wrong key.
Signatures provide integrity, authenticity and nonrepudiation, but not confidentiality. Common algorithms are RSA signatures, ECDSA, EdDSA and, for post-quantum security, ML-DSA. Code signing uses signatures so that users can verify software comes from its publisher unchanged.
Signing and verifying
Public key infrastructure
A public key is useful only if you know whose it is. A public key infrastructure (PKI) binds public keys to identities with digital certificates (X.509), which contain the subject's name, public key, validity dates, issuer and the issuer's signature. A certificate authority (CA) issues and signs certificates after a registration authority (RA) verifies the requester's identity.
Trust flows from a root CA, kept offline and highly protected, through intermediate CAs that issue end-entity certificates; relying parties validate the chain up to a trusted root. Certificates are revoked before expiry, for example after key compromise, and status is checked through certificate revocation lists (CRLs), the Online Certificate Status Protocol (OCSP) or OCSP stapling, in which the server supplies a recent signed status. Certificate pinning restricts which certificates an application accepts for a service. Quantum key distribution (QKD) is a different key distribution method that uses quantum states of photons so that eavesdropping disturbs the signal and is detected; it needs dedicated hardware and links and does not replace authentication.
When a browser connects to a website, it validates the server's certificate in several steps, and a failure at any step should stop the connection. It checks that the name in the certificate matches the site requested, that the current date is within the validity period, that each certificate in the chain is signed by the next one up, that the chain ends at a root CA in its trusted store, that the certificate is permitted for server authentication and that it has not been revoked. An attacker who presents a self-signed certificate, or a valid certificate for a different domain, fails these checks.
The root CA is kept offline because its compromise would be catastrophic: an attacker with the root key could issue trusted certificates for any name, and every certificate under that root would have to be replaced. Intermediate CAs limit the damage, because if an intermediate is compromised, the root can revoke it and issue a new one without rebuilding trust in every client. Organisations that run an internal PKI apply the same design, with an offline root in a safe and online issuing CAs protected by HSMs.
The following diagram shows the response to a compromised private key.

Validating a server certificate
A revoked certificate
A web server's private key was stolen yesterday. The certificate is valid for another ten months. What must happen so that browsers stop trusting the stolen key?
The organisation must ask the CA to revoke the certificate, generate a new key pair and obtain a new certificate. Revocation is published through the CA's CRL and OCSP responder so that relying parties reject the old certificate. Simply installing a new certificate is not enough, because an attacker could still present the old, unexpired certificate with the stolen key.
Which key does a recipient use to verify a digital signature?
Show answer
The signer's public key.
Exam Tips
Remember for the exam
- Hashes give integrity; HMACs add authenticity between key holders.
- Signatures provide integrity, authenticity and nonrepudiation, not confidentiality.
- Keep the root CA offline.
- Revoke certificates whose keys are compromised.