Match the tool to the goal. Want a fingerprint of data: hash. Want to detect tampering between parties who share a key: MAC. Want anyone to verify who produced something: digital signature. Want only key holders to read it: encryption. Many designs need two of these together.
The four tools
- Hash: input in, fixed-size fingerprint out. No key, cannot be reversed. Anyone can compute it.
- MAC (such as HMAC): a hash with a secret key. Only holders of the key can create or check the tag. Both sides hold the same key.
- Digital signature: made with a private key, checked with a public key. Anyone can verify, only the key owner can sign.
- Encryption: turns data into unreadable ciphertext using a key. Reversible with the key. Use an authenticated mode.
Pick by question
- Is this file the one I expected? Compare a published hash, ideally one obtained through a trusted channel. Our post on verifying a SHA-256 checksum shows the habit.
- Has this message from my partner been changed? MAC, with a per-partner key. See HMAC for request signing.
- Can a third party prove this came from us? Signature. A MAC cannot do it, since both sides hold the key.
- Must this stay private at rest or in transit? Encryption with an AEAD, and keys kept separately.
- Do I need to store a password? None of these directly: use a slow password hash such as Argon2id.
- Do I need to hide a value but still search it? Consider a keyed hash in a separate column, and weigh the leak of equality.
Combining them
- Encryption alone does not detect tampering. Use an AEAD, or encrypt-then-MAC.
- A signature over a hash of a large file is how most signing works: hash first, sign the digest.
- A hash alone, published next to the file on the same server, proves little. An attacker who can change the file can change the hash.
Common confusion
Encoding is none of these; see Base64 is not encryption. A signed token is readable. An encrypted blob is not automatically authentic. A hash is not a way to hide short secrets like phone numbers, because guessing all possibilities is quick.
Quick check
Can I hash an email address to anonymize it?
Not reliably. Anyone with a list of emails can hash them and compare. Treat it as pseudonymous at best and use a keyed hash if you need more.
Which is faster, MAC or signature?
A MAC is typically much faster, which is one reason it suits high-volume service calls where both ends are trusted partners.
Last reviewed: 19 October 2026.