What's changed: Initial version
2.2Hashing and digital signatures
Covers hash functions (such as SHA-256) with the properties of one-wayness and collision resistance, MAC/HMAC which uses a shared key and a hash function to detect message tampering, digital signatures, which use public-key cryptography to also guarantee authenticity and non-repudiation, and timestamping, code signing, and XML digital signatures.
When selecting a technology to protect a system's integrity and authenticity, the first question a practitioner must ask is "what exactly needs to be guaranteed?" Whether the goal is simply to confirm "was this not tampered with in transit," or to "prove to a third party who created this, in a way the creator cannot later deny," determines whether MAC/HMAC or a digital signature is the right choice. Building on the properties of hash functions, this section covers the decision axis for that choice.
2.2.1Hash functions (one-wayness, collision resistance, SHA-256)
- A hash function produces a fixed-length hash value (message digest) from data of arbitrary length. Its security rests on two properties: one-wayness (the original data cannot be recovered from the hash value) and collision resistance (it is computationally infeasible for two different inputs to produce the same hash value).
- SHA-256 outputs a 256-bit hash value and is a currently recommended hash function (part of the SHA-2 family). The older MD5 and SHA-1 have had actual collisions found and are compromised schemes that should be avoided in new systems.
2.2.2MAC/HMAC (message authentication code)
- A MAC (message authentication code) is a check value computed from a message and a shared key pre-established between sender and receiver. If the receiver recomputes the MAC with the same key and it matches, this confirms integrity (no tampering in transit) and a limited form of authenticity (the sender holds the shared key).
- HMAC is the standard way to construct a MAC using a hash function such as SHA-256. Because anyone holding the shared key can perform the same computation, a MAC cannot provide non-repudiation (proving to a third party who the sender was)—this is the decisive difference from a digital signature.
The most frequently tested contrast is "MAC/HMAC uses a shared-key scheme, so it guarantees only integrity and a limited form of authenticity, with no non-repudiation; a digital signature uses public-key cryptography, so it guarantees integrity, authenticity, and non-repudiation." Whether "proof to a third party is required" is the decisive axis separating MAC/HMAC from digital signatures.
2.2.3Digital signatures, timestamping, code signing, and XML digital signatures
- A digital signature works by having the sender encrypt (sign) the hash value of a message with their own private key, and the receiver verify it with the sender's public key. Because only the signer possesses the private key, this guarantees integrity and authenticity, plus non-repudiation ("only the signer could have signed it, so it cannot be denied later")—beyond what a MAC provides.
- A timestamp is a mechanism by which a trusted third party (a Time-Stamping Authority) certifies that certain data definitely existed at a given time. Combined with a digital signature, it also proves when the signature was made, strengthening the long-term evidentiary value of documents such as contracts.
- Code signing is a mechanism where a software distributor attaches a digital signature to an executable, allowing users to verify that it has "not been tampered with" and comes from a "legitimate distributor." XML digital signature is a standard for applying a digital signature to part or all of an XML document, used to protect messages in web services (such as SOAP).
Suppose a financial institution's information security lead must address two different requirements. Requirement A: "for internal API communication between branch offices, we want a fast way to confirm there was no tampering in transit, but the communication happens over a closed network and no proof to third parties is needed." Requirement B: "we want to retain evidence that a customer agreed to an electronic contract in a form that can rebut, to a third party (e.g., a court), any later claim by that customer that they never agreed." Requirement A needs only integrity confirmation, with no non-repudiation required, so it is rational to choose the lighter-weight HMAC (shared key plus hash function)—pre-sharing a key between branches over a closed network is practical, and the computational cost of a digital signature using public-key cryptography is unnecessary. Requirement B, on the other hand, has non-repudiation itself as its purpose—proving to a third party that the customer cannot later deny having agreed—so a digital signature (signed with the customer's own private key) is essential. If it is further necessary to retain "when the agreement was made" as legal evidence, appending a timestamp to the signature, certified by a trusted third party (a Time-Stamping Authority), strengthens the long-term evidentiary value of the electronic contract. If, in the Requirement A scenario, a new requirement is later added that says "we also want to prove to an external auditor that the other party really is that branch," a MAC—where anyone holding the shared key can perform the same computation—cannot provide proof to a third party, so a switch to a digital signature becomes necessary. In this way, the lead always discerns from business requirements "whether integrity alone suffices, or whether authenticity and non-repudiation must also be proven to a third party," and chooses between MAC/HMAC and digital signatures accordingly.
| Aspect | MAC/HMAC | Digital signature |
|---|---|---|
| Key used | Shared key (common to sender and receiver) | Signer's private key; verifier uses the public key |
| Properties guaranteed | Integrity plus limited authenticity | Integrity, authenticity, and non-repudiation |
| Proof to a third party | Not possible (anyone with the shared key can compute it) | Possible (only the signer holds the private key) |
Trap: "Because HMAC uses a hash function, it also guarantees non-repudiation like a digital signature" is wrong—with HMAC, anyone holding the shared key can perform the same computation, so the premise of non-repudiation ("only the creator could have produced it") does not hold. If non-repudiation is required, a digital signature based on public-key cryptography must be used. Also wrong: "a hash function only needs one-wayness"—collision resistance (that two different inputs cannot practically produce the same hash value) is equally essential, and schemes such as MD5 and SHA-1, where collisions have been found, should not be used as the basis for signatures or MACs.
2.2.4Section summary
- A hash function's security requires both one-wayness and collision resistance. MD5 and SHA-1 have had collisions found; use SHA-256 or similar instead
- MAC/HMAC uses a shared-key scheme, guaranteeing integrity plus limited authenticity only (no non-repudiation)
- Digital signatures use public-key cryptography to guarantee integrity, authenticity, and non-repudiation. Combined with a timestamp, they can also prove "when"
Sign in to track progress — Log in.
Quick check
(just a quick review)Q1. For internal API traffic between branch offices, the goal is only to quickly confirm that no tampering occurred in transit. The traffic stays within a closed network, and there is no need to prove the sender's identity to a third party. Which scheme is most appropriate?
Q2. The goal is to retain evidence that a customer agreed to an electronic contract, in a form that can rebut, to a third party such as a court, any later claim by the customer that they never agreed. Which combination of technologies most appropriately satisfies this requirement?
Q3. A software distributor wants to let users verify that a distributed executable "has not been tampered with and comes from the legitimate distributor." Which technology is most appropriate?

