SHA hash functions: integrity, collisions and appropriate use
What SHA hashes provide, how SHA-2 and SHA-3 differ, and why hashing is neither encryption nor a complete password-storage scheme.

On this page
A cryptographic hash maps input data to a fixed-size digest. SHA names a family of standardized hash algorithms. A hash can help check integrity, but it does not encrypt data, keep the input confidential or authenticate a sender by itself.
Security properties
- Preimage resistance: given a digest, finding an input that produces it should be computationally difficult.
- Second-preimage resistance: given one input, finding a different input with the same digest should be difficult.
- Collision resistance: finding any two distinct inputs with the same digest should be difficult.
Collisions must exist because a fixed-size output space cannot uniquely represent every possible input. Collision resistance concerns the difficulty of finding them, not a promise that digests are unique. A large change in output after a small input change is a different property from second-preimage resistance.
SHA families and history
SHA-1, SHA-2 and SHA-3 are not simply successive settings of one algorithm. NIST standardized different designs over time. SHA-2 includes SHA-256 and SHA-512; SHA-3 is based on Keccak and uses a different construction. SHA-3 does not make correctly selected SHA-2 uses automatically obsolete.
SHA-1 has practical collision weaknesses and should not be selected for new collision-resistant applications. An algorithm's suitability also depends on the protocol and required security strength: a generic family name is not a complete deployment decision.
How hashing works
A hash implementation consumes bytes and produces a digest of the algorithm's specified length. SHA-2 processes padded message blocks through its defined compression construction; SHA-3 uses a sponge construction. Do not assume that the internal steps of SHA-256 also describe SHA-3.
For a text such as “Hello, World!”, encoding and exact bytes matter. A trailing newline, another encoding or different capitalization changes the input. Hexadecimal and Base64 are representations of a digest, not additional encryption.
Integrity and authentication
To verify a download, calculate its digest and compare it with an expected value obtained from a trustworthy source. Sending an untrusted file and an untrusted digest together does not stop an attacker replacing both.
A message authentication code, such as an appropriate HMAC construction, can authenticate data between parties sharing a secret. Digital signatures use a defined signing scheme and public-key verification; describing every signature as “encrypting a hash with a private key” is inaccurate.
TLS and other secure protocols may use hashes within larger constructions. Hashing alone supplies neither their confidentiality nor their complete identity checks. It cannot establish regulatory compliance on its own.
Password storage
Do not store passwords as plain SHA digests. General-purpose fast hashes make large-scale guessing efficient. Password storage needs a dedicated salted, costed password-hashing scheme and parameters appropriate to the application and current guidance. See authentication for the surrounding account-security responsibilities.
A salt is not a secret encryption key. It helps distinguish otherwise identical passwords and defeats precomputed tables, but does not turn a weak password into a strong one or prevent all offline guessing.
Choosing and maintaining a design
Use an established implementation and the algorithm required by the complete protocol. Avoid homemade combinations, especially constructions that assume a plain digest proves who sent a message. Maintain a migration path when a protocol or algorithm is deprecated.
Quantum security analysis depends on the property and output length under consideration; it is not equivalent to factoring-based public-key cryptography. Lattice-based encryption or signatures are not simply replacements for SHA hash functions. Follow the relevant standards rather than treating all post-quantum proposals as one interchangeable category.
References
Written by Alex Hovy.
← Back to BlogsContinue reading
Replacing an identity server: ASP.NET Core Identity and OpenIddict
Migration considerations for user management, OAuth/OpenID Connect contracts, credentials and operations, with clear distinctions between identity products.
Authorisation: resource permissions and trusted enforcement
Design understandable access rules, enforce object-level permissions and account for service boundaries, caching and revocation.
Authentication: passwords, MFA, sessions and tokens
Separate identity verification from permissions, and understand the responsibilities around passwords, MFA, sessions, JWT validation and account recovery.