Encryption vs Hashing vs Encoding: One Table to Tell Them Apart

The difference comes down to three dimensions: reversibility, keys, and output shape. Confusing them is not a quiz mistake but a real incident — passwords stored as Base64 (which is plaintext), signature checks that confuse decoding with verification, installers trusted after a single MD5 comparison.

One Table, Three Dimensions

Dimension Encoding Hashing Encryption
Purpose Fit a channel or format Verify integrity, fingerprint Confidentiality
Reversibility Reversible, table is public Irreversible, information is discarded Reversible, given the key
Key None None (password hashing adds salt) Required and secret
Output shape Text inside a charset Fixed-length digest Ciphertext roughly the size of plaintext
Same input Deterministic Deterministic Deterministic modes yes; random IV differs each time
Examples Base64, URL encoding, Hex MD5, SHA-256, bcrypt AES-GCM, ChaCha20, RSA

In one line: encoding re-represents, hashing fingerprints, encryption locks. Locks need keys, fingerprints cannot be reversed, and anyone can re-represent.

Encoding Is Not Encryption: One Step Back

"Base64 output looks like gibberish, so it must be encrypted" is the classic mistake. The gibberish feeling comes only from a different alphabet; the table is a public standard and decoding needs no secret:

echo -n "admin:123456" | base64     # -> YWRtaW46MTIzNDU2
echo "YWRtaW46MTIzNDU2" | base64 -d # -> admin:123456 (anyone, one step)

No key participates, so no confidentiality exists. Base64's real job is transport compatibility: letting binary data cross text-only channels such as email bodies, JSON strings, or URL parameters. Details in Base64 encoding explained.

URL encoding (%E4%BD%A0) and Unicode escapes (\u4f60) belong to the same category: they answer whether a character can legally appear in a given format, nothing about secrecy. One test decides it — if decoding needs no secret, it is not encryption.

Why Hashing Is Irreversible: "Decryption Sites" Are Looking Up

SHA-256 compresses input of any length into a fixed 32-byte digest, and information is discarded along the way: only 2²⁵⁶ outputs exist while inputs are infinite, so countless inputs share one digest. There is simply not enough information in a digest to rebuild the original. It is not that the algorithm hides something; the information is gone.

That is why "MD5 decryption" sites do not reverse anything. They look up: precompute hashes of massive candidate lists, match yours, and return the hit. That is the whole risk of bare-hash password storage — an attacker needs a large table, not an understanding of SHA-256.

The correct posture for passwords is salt plus a slow hash: a salt makes the same password produce different digests per user, breaking bulk rainbow-table lookups, and slowness raises each guess from nanoseconds to tens of milliseconds. Algorithms and parameters in the password hashing guide.

The Core of Encryption Is the Key

The AES and ChaCha20 specifications are public, and confidentiality rests entirely on the key. Three engineering consequences follow:

  1. Key management fails more often than algorithm choice: keys hardcoded in source or committed in config files cause more incidents than a misused ECB mode.
  2. Public algorithms are not a weakness: Kerckhoffs' principle says everything except the key may be public and the system should still hold.
  3. Mode choice matters just as much: AES-ECB emits identical ciphertext blocks for identical plaintext blocks (the ECB penguin), while AES-256-GCM provides confidentiality and an integrity check together. Mode comparison in AES encryption modes.

Five Scenarios, Five Tools

Task Correct tool Do not use
Store login passwords bcrypt / argon2 (salted slow hash) MD5, Base64, AES (reversible means retrievable)
Verify a download was not altered SHA-256 against the publisher's digest MD5 (collisions are constructible)
Push binary through a text channel Base64 / Base64URL encryption (do not add key management to a keyless job)
Sensitive database fields AES-GCM or another authenticated cipher Base64, hashing (irreversible means unreadable forever)
Tamper-proof API payloads HMAC-SHA256, a keyed hash concatenated bare hashes

The fourth row is the one people invert: irreversibility means data "stored" as a hash can never be read back. Hashing a phone number for later display is impossible by design, and storing it as Base64 is plaintext with extra steps. This case needs encryption, not encoding or hashing.

Same Input, Three Outputs

import base64, hashlib
msg = b'hello world'

print(base64.b64encode(msg).decode())            # aGVsbG8gd29ybGQ=   <- encoding: reversible, keyless
print(base64.b64decode(base64.b64encode(msg)))   # b'hello world'      <- one step back
print(hashlib.sha256(msg).hexdigest())           # b94d27b9934d3e08…   <- hashing: one-way
print(len(hashlib.sha256(msg).digest()))         # 32 (256 bit, independent of input length)

Then run AES-CBC through OpenSSL with an explicit key and IV so the result is reproducible:

echo -n "hello world" | openssl enc -aes-128-cbc \
  -K 000102030405060708090a0b0c0d0e0f \
  -iv f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff | xxd -p
# -> ciphertext; change -K to any other 16 bytes and the output changes completely

Those three shapes are the boundary: encoding changed the representation, hashing discarded information, encryption locked the data. To check it yourself, the AES encrypt/decrypt, text hash, and Base64 converter tools run locally in the browser and upload nothing.

Frequently Asked Questions

Can Base64 be used to "encrypt" passwords?

No. Base64 is an encoding: no key, a public alphabet, and anyone can reverse it in one step. Storing admin123 as YWRtaW4xMjM= in a database is identical to storing plaintext — "looks like gibberish" does not mean "confidential". Passwords belong in bcrypt/argon2 slow hashes.

If hashing is irreversible, why can it still be cracked?

Irreversible means you cannot derive the input from the hash — but attackers don't need to: they enumerate candidate passwords, hash each and compare. Bare MD5/SHA-256 password storage is unsafe because modern GPUs compute billions of hashes per second. The defence is salt + slow hash (bcrypt/argon2) to make each guess expensive.

The same file always produces the same hash — isn't that insecure?

Quite the opposite — determinism is exactly what makes hashes usable for integrity: identical input must give identical output, and a single changed byte produces a completely different hash (avalanche). "Security" depends on the use: SHA-256 is fine for verifying downloads; password storage needs salting and a slow hash, otherwise determinism just helps rainbow tables.

Is the Base64 in a JWT encrypted content?

No. A JWT's three segments are Base64URL-encoded Header, Payload and Signature — anyone can decode and read the first two (this site has a [JWT parser](/jwt-parser.html)). What prevents tampering is the third segment, the signature: modifying the Payload without recomputing the signature fails verification. So never put sensitive plaintext in a JWT payload.

← Back to Blog