- Which hash algorithm should I use for file integrity?
- SHA-256 for new systems — widely supported, no known vulnerabilities, sufficient speed. SHA-512 for slightly higher security margin at the cost of larger hash output. MD5 only for legacy compatibility where SHA-256 is not supported. Never use MD5 for security-critical verification.
- Can two different files have the same hash?
- In theory (hash collision), but the probability is astronomically small for SHA-256. For MD5 and SHA-1, collisions are theoretically possible and have been demonstrated under controlled conditions — making them unsuitable for security use but still reliable for detecting accidental corruption.
- What is HMAC and how is it different from a file hash?
- A file hash is computed from data alone and verifies integrity (has the data changed?). HMAC (Hash-based Message Authentication Code) uses a secret key alongside the data, verifying both integrity and authenticity (did someone with the key produce this?). HMAC prevents an attacker from substituting a file and recalculating the hash.