Hashing vs Encryption: How They Work, and Why SHA-256 Is Wrong for Passwords
· security, hashing, encryption, passwords, cryptography, argon2
The short video above draws a line that many production bugs ignore: hashing and encryption both protect data, but they are not interchangeable. Mix them up — store passwords with a reversible cipher, or protect a backup with a one-way hash you can never restore — and you have a security defect, not a style preference. This article explains how each one actually works, why a fast general-purpose hash such as SHA-256 is the wrong tool for passwords, and what official guidance from NIST and OWASP says you should use instead. Where the video simplifies, or where a claim is the video’s wording rather than a figure published by a standards body, we say so. We do not invent cracking speeds or work factors those sources have not published.
The rule the video gets right
The closing line is the right decision test. If you need the original data back later, encrypt it. If you only need to check that a value matches something you saw before, hash it. OWASP’s Password Storage Cheat Sheet draws the same line: hashing is the right approach for password validation because it is one-way; encryption is appropriate for data you must display or restore later, and is usually the wrong way to store a password. The rest of this article is about the details that turn that rule into a design you can defend.
How encryption actually works
Encryption transforms readable data (plaintext) into ciphertext using an algorithm and a key. With the right key, you can reverse the process and recover the original bytes. Without the key, a well-designed scheme is intended to make that recovery infeasible. The video’s “two-way street” and “lock and key” language is a fair description of that idea, and it is incomplete in three ways that matter in production.
First, if you lose the key, the ciphertext is as useless as a hash: you will not get the backup back. Key generation, storage, rotation, and access control are the hard part of encryption. The OWASP Cryptographic Storage Cheat Sheet is explicit that passwords should not be stored with reversible encryption, and that data you do encrypt should be protected with additional layers, not with cryptography alone.
Second, there is more than one kind of key. Symmetric encryption uses the same secret to lock and unlock the data. AES, specified in FIPS 197, is the usual modern choice; OWASP recommends AES with a key of at least 128 bits, ideally 256 bits, in a secure mode. Asymmetric (public-key) encryption uses a public key to encrypt and a private key to decrypt. In practice, systems often use a hybrid design: a public-key operation establishes or wraps a short-lived symmetric key, and that symmetric key encrypts the bulk data. If RSA is used, OWASP says the key should be at least 2048 bits. For what is verified about attacking that size, see The Rumor That AI Broke RSA-2048.
Third, confidentiality is not the same as integrity. Older modes can hide a message and still leave it open to undetected tampering. OWASP’s guidance is to prefer authenticated modes such as GCM or CCM, which protect integrity and authenticity as well as secrecy. If those are not available, a mode such as CTR or CBC should be paired with a separate authenticity check, for example encrypt-then-MAC.
That is also why the video’s HTTPS example is directionally right and technically thin. The connection between a browser and a website is protected by TLS. In TLS 1.3, specified in RFC 8446, the record protection is an AEAD scheme: it encrypts the bytes and authenticates them in the same construction. The handshake also uses hash-based functions — a transcript hash and HKDF — and certificates that themselves depend on hash-and-sign designs. HTTPS is not “encryption instead of hashing.” It is a protocol that uses both, for different jobs. A database backup, the video’s other example, is a cleaner case for encryption as the primary tool: you must be able to restore the original records. You may still hash or sign the backup to detect change, but the restore path is decryption, not “unhashing.” Encryption can be applied at the application, the database, the filesystem, or the hardware. OWASP notes that the right layer depends on the threat: disk encryption helps if someone steals the server, and does nothing if an attacker is already logged in as the application user.
How a cryptographic hash actually works
A cryptographic hash function takes an input of essentially arbitrary length and produces a fixed-length digest. There is no decryption step. The Secure Hash Standard, FIPS 180-4, describes SHA-1 and the SHA-2 family, including SHA-256, as iterative, one-way hash functions that produce a condensed representation called a message digest. For SHA-256 the digest is 256 bits. FIPS 180-4 also states the integrity property the video is pointing at: any change to the message will, with a very high probability, result in a different message digest. That is the official version of “change even one letter and the whole hash changes.” The informal name is the avalanche effect. The standard does not promise that every output bit flips, or claim a mathematical impossibility of finding another input with the same digest. The designed properties are one-way behavior (it should be infeasible to recover a preimage from the digest), second-preimage resistance, and collision resistance. “Infeasible” is not the same as “a determined attacker will never guess a weak input,” which is why password storage is a different problem.
The video says hashing has “no key.” That is true of SHA-256 itself, and of other unkeyed hash functions in FIPS 180-4 and SHA-3 (FIPS 202). It is not true of every construction that has “hash” in the name. HMAC, specified in RFC 2104, is a keyed hash used to check integrity and authenticity when two parties already share a secret — closer to a signature with a shared key than to password storage. JSON Web Tokens are often signed with HMAC; that is a different design from how you store a user’s password, and it is covered in Sessions vs JWTs. Hashes are the right tool when you need a fingerprint: checking that a downloaded package matches the published digest, or binding a TLS handshake transcript. You compare digests. You do not expect to get the original file back from the digest alone.
Why password storage is not “just SHA-256”
The classic example in the video is the right one. When you sign up, the server should not store the password you typed; it should store a password hash. When you log in, the server hashes the value you submitted and compares it to the stored verifier. A match means you presented the same secret, not that the server “decrypted your password.”
NIST’s current authenticator requirements in SP 800-63B-4 are blunt. Verifiers shall store passwords in a form that is resistant to offline attacks. Passwords shall be salted and hashed using a suitable password hashing scheme. Those schemes take a password, a salt, and a cost factor, and they exist to make each guess expensive for an attacker who has obtained the hash file. The cost factor should be as high as practical without harming the verifier, and it should be increased over time as computers get faster. The salt shall be at least 32 bits and chosen to avoid collisions among stored hashes. Both the salt and the hash shall be stored, and a reference to the scheme and cost factor should be stored so you can migrate later.
OWASP is just as direct about the algorithm family. Passwords should never be stored in plaintext. They must be protected with strong, slow algorithms such as Argon2id, bcrypt, or PBKDF2, and a unique salt must be added to each password so that precomputed tables (rainbow tables) do not work. Fast hashing algorithms such as SHA-256 are not suitable for password storage because they allow attackers to perform large numbers of guesses quickly. That last sentence is the official version of the line the video stresses. The video says attackers can try “billions of guesses.” That number is the video’s wording, not a figure we found in the OWASP cheat sheet or in NIST SP 800-63B-4, so we do not treat “billions” as an official measurement. The official claim is qualitative and still decisive: a fast hash lets an attacker try a large number of candidates quickly; a slow, memory-hard password hash makes that attack much more expensive.
It is also worth being precise about “there is no way to turn the hash back into the original.” For a modern password hash of a strong, unique secret, recovering that secret from the digest alone should be impractical. OWASP even says it is impossible to “decrypt” a hash and obtain the original plaintext, which is a useful shorthand and slightly loose. Nobody decrypts a hash. People guess: they take a candidate, run the same slow function with the same salt, and compare. If the password is weak, or if you used a fast hash, that loop can succeed.
What “slow” actually means: Argon2id, bcrypt, and the rest
The video recommends a slow password hash such as Argon2id or bcrypt, and says these also add a random salt so that two people with the same password get different hashes. The direction is right. Official guidance is more ranked, and the salt is a required input, not a property you get just by naming the algorithm.
OWASP’s current preference for new systems is Argon2id, the variant of Argon2 (winner of the 2015 Password Hashing Competition) that the cheat sheet recommends for a balance against side-channel and GPU-based attacks. Parameter definitions are in RFC 9106. Argon2id has three main cost parameters: memory in KiB (m), passes (t), and parallelism (p). OWASP’s headline minimum is 19 MiB of memory, an iteration count of 2, and one degree of parallelism (m=19456, t=2, p=1). The same page lists equivalent minimums that trade RAM for more passes. Benchmark those parameters on the hardware that will verify logins. As a general rule, OWASP says calculating a hash should take less than one second; too slow, and an attacker can turn login attempts into a denial of service.
If Argon2id is not available, OWASP’s next recommendation is scrypt, with a minimum of N=2^17 (128 MiB), r=8, p=1, or listed equivalents.
bcrypt is presented in the video as a peer of Argon2id. Officially, OWASP says bcrypt should be used for password storage in legacy systems where Argon2 and scrypt are not available, with a work factor of 10 or more, as large as the verification servers will allow. Most implementations truncate at 72 bytes, so you must enforce that maximum (or less, if your library is tighter). Pre-hashing a long password before bcrypt is easy to get wrong — OWASP warns about null bytes and “password shucking” — so read that section of the cheat sheet rather than inventing a SHA-512 wrapper.
If you need FIPS 140 validated implementations, OWASP and NIST point at PBKDF2. OWASP’s preferred form is PBKDF2 with HMAC-SHA-256 and a work factor of 600,000 iterations or more. It also lists 220,000 iterations for HMAC-SHA-512, and treats HMAC-SHA-1 as legacy only. NIST SP 800-63B-4 says an approved scheme from the latest SP 800-132 or updated NIST password-hashing guidance should be used.
A well-behaved library generates a unique random salt, mixes it into the hash, and stores the salt, the parameters, and the digest in one encoded string (often in the PHC or modular format). That is how two accounts with the same password get different stored values, and how you can raise the work factor later and re-hash on the next successful login. If you “just SHA-256 the password and store the hex,” you have done none of that: even with a homemade salt, you still have a fast hash.
A pepper is different from a salt. OWASP describes it as an extra secret, shared across passwords, stored outside the password database — in a secrets vault or an HSM — so that a stolen SQL dump is not enough by itself. NIST similarly says verifiers should consider an additional keyed iteration with a secret known only to the verifier, ideally in a hardware-protected area. A pepper is defense in depth, not a substitute for a slow, salted hash, and rotating it usually means a password reset.
How the login comparison is supposed to work
The video’s login story is the correct shape. You never need the original password after signup. You store the verifier. On each login you compute a new verifier from the typed password and the stored salt and parameters, and you compare the two.
Store the algorithm identifier and the work factor with the hash so you can upgrade. OWASP describes a transition period in which old and new hashes coexist, and two upgrade paths for legacy schemes such as MD5 or SHA-1: expire stale hashes and force a reset, or wrap the old hash inside a modern one and replace that wrap with a direct hash at the next login. Wrapping is a migration tactic, not a recommendation for new stores.
Do not truncate the password. NIST says the verifier shall request the password in full and verify the entire submitted value. That matters especially with bcrypt’s 72-byte cap: if you silently drop the rest, two long passwords that share a prefix can collide. NIST SP 800-63B-4 also requires a minimum length (15 characters when the password is a single-factor mechanism; eight when it is used as part of multi-factor authentication), asks you to allow at least 64 characters, and says you shall not impose other composition rules or periodic rotation. You shall compare new passwords against a blocklist of common or breached values.
And do not confuse “the hash matched” with “the account is safe.” A password is not phishing-resistant, which NIST states plainly. Session design, multi-factor authentication, and credential-stuffing defenses still belong in the same system.
Common ways this mix-up becomes a bug
The failure modes are predictable, and most of them are the video’s warning in concrete form.
Encrypting passwords. Because encryption is reversible, anyone who obtains the key can recover every password in the table. OWASP allows this only in edge cases where the application must replay the plaintext password to another system that has no modern delegation path, and tells you to change the architecture instead whenever you can. “Password encryption” in a library name is sometimes hashing in disguise; read the docs.
Hashing data you must read again. If you SHA-256 a backup, a user’s address, or a document you need to display, you cannot get the original back. Confidentiality for data at rest is encryption (plus access control). A hash can sit beside the ciphertext as an integrity check.
Using SHA-256, SHA-1, or MD5 as the password hash, even with a salt. A salt stops rainbow tables; it does not make a fast function slow. OWASP’s rejection of SHA-256 for password storage is about speed, not about SHA-256 being “broken” as a general hash. SHA-256 remains appropriate for integrity fingerprints and for constructions such as HMAC-SHA-256. The bug is the use case.
Rolling your own mix. Concatenating a salt, hashing once with SHA-256, then “iterating a few times” is how many private schemes are born. Use a maintained library for Argon2id, scrypt, bcrypt, or PBKDF2, with parameters at or above the published minimums.
Ignoring bcrypt’s 72-byte limit, or pre-hashing it carelessly. Silent truncation and password shucking are documented failure modes, not trivia.
Treating HTTPS as a substitute for storage protection, or storing API keys the wrong way. TLS protects data in transit; it does not hash or encrypt the password column on your disk. You still need a password hash at rest, and encryption for backups and other recoverable secrets. If you only ever need to verify a presented secret, a password-style hash is usually the right idea. If the application must display or replay the secret, you are in encryption-and-vault territory.
What this means if you are building agents or internal tools
The same mix-up shows up as soon as software can call tools, hold tokens, or log prompts. An agent that stores user passwords, mailbox credentials, or raw API keys in a prompt log is doing the equivalent of a plaintext password column. Secrets that must be replayed to a third-party API belong in a vault, under access control, with encryption at rest. Secrets you only need to recognize should be stored as verifiers, not as reversible copies, and they should not be written into context. A system prompt is not a security boundary: if the agent can run a command or send a request, authorization has to live in the tool layer, and the credentials that layer uses have to be stored with the same hashing-versus-encryption discipline you would demand of a login service. For the broader production pattern, see How Companies Build Their AI Assistant and From a 10-Minute Claude Agent to Production-Grade AI Agents.
The caveats worth keeping next to the video
The video is a good mnemonic, not a complete standard. Encryption is two-way only if you still have the key, and it should be authenticated, not “just AES” in an outdated mode. Hashing is one-way in the sense that you do not decrypt a digest; guessing a weak input is still an attack. Unkeyed hash functions have no key; HMAC and peppers do. SHA-256 is a solid general-purpose hash and a poor password hash. Argon2id is the first recommendation for new password stores; bcrypt remains acceptable in legacy systems with a work factor of at least 10 and a 72-byte input cap. Official documents do not publish the video’s “billions of guesses” figure; they publish the reason fast hashes are the wrong tool. If you need the data back, encrypt it and protect the key. If you only need to check a secret, hash it with a slow, salted password-hashing scheme — not with SHA-256 alone.
How RankCore AI can help
Choosing a hash or a cipher is one decision in a larger system: login and session design, secret storage, tool permissions, audit logs that do not leak credentials, and agents that can act without being handed a plaintext password. That is the work RankCore AI does for businesses that need custom agents and internal tools built with those boundaries in place. If you want help designing or building that stack, visit rankcore.ai and tell us about the workflow. We will not invent case studies or metrics. We will start from the secrets the system must hold, the actions that need a human in the loop, and the official guidance above, and say honestly where a vault, a password hash, or a tighter design is the right fit.
Official sources
Want to go deeper?
Our step-by-step video courses turn these ideas into results.
Comments
No comments yet — be the first.