Encoding vs encryption vs hashing
Stage 0 · Lesson 6 · 15 minutes · Requires Lessons 1–5
The one-line answer
Encoding changes format and anyone can reverse it. Encryption hides data and needs a key to reverse. Hashing is one-way and cannot be reversed at all.
Why you should care
This is the most commonly confused topic in beginner security, and the confusion causes real damage.
Developers ship "encrypted" data that's actually Base64 — readable by anyone in two seconds. Beginners announce they've "cracked" a hash when they've decoded a string. Interviewers ask this question constantly precisely because it separates people who understand security from people who've memorised tool names.
Get this right once and it stays right forever.
How it actually works
Encoding — format, not security
Purpose: make data safe to transmit or store in a particular context. Reversible: yes, by anyone, with no secret. Security value: zero.
Base64 is the one you'll see constantly:
Original: hello world
Base64: aGVsbG8gd29ybGQ=Anyone can reverse that instantly. It exists because some systems only handle plain text safely, so binary data gets converted into a limited character set.
You'll also meet:
- URL encoding —
%20for space (Lesson 5) - HTML entities —
<for< - Hex —
68656c6c6fforhello
Recognising Base64: letters, numbers, + and /, length divisible by 4, often ending in = or ==. That trailing equals sign is a strong tell.
The rule: if there's no key, it's not encryption. Encoding protects nothing.
Encryption — confidentiality with a key
Purpose: make data unreadable to anyone without the key. Reversible: yes, but only with the correct key. Security value: high, when implemented correctly.
Two families:
Symmetric — same key encrypts and decrypts. Fast. Used for bulk data. The standard is AES. The problem: both parties need the key, and getting it to them safely is hard.
Asymmetric — a key pair. The public key encrypts, the private key decrypts. Slower, but solves key distribution. RSA and elliptic-curve algorithms are the common ones.
How HTTPS actually uses both: asymmetric encryption is used briefly at the start to agree on a shared secret, then symmetric encryption handles the actual traffic because it's far faster. That handshake is the TLS handshake.
Hashing — one-way fingerprint
Purpose: verify integrity, or store passwords safely. Reversible: no. Never. Not with any key. Security value: high for the right job.
A hash function takes any input and produces a fixed-length output:
hello → 5d41402abc4b2a76b9719d911017c592 (MD5)
hello! → 5a8dd3ad0756a93ded72b823b19dd877 (MD5)Note that a tiny input change produces a completely different output. That's the avalanche effect, and it's what makes hashes useful for detecting tampering.
Properties of a good hash:
- Same input always gives the same output
- Fixed output length regardless of input size
- Infeasible to reverse
- Infeasible to find two inputs with the same output (collision resistance)
Which to use:
| Algorithm | Status | Use for |
|---|---|---|
| MD5 | Broken | File checksums only, never security |
| SHA-1 | Broken | Nothing new |
| SHA-256 | Strong | Integrity, signatures |
| bcrypt / scrypt / Argon2 | Strong | Passwords — this is the answer |
Why passwords need bcrypt, not SHA-256: SHA-256 is designed to be fast, which means an attacker can try billions of guesses per second. Password hashes should be deliberately slow. bcrypt and Argon2 are tunable — you can make each hash take a fraction of a second, which is unnoticeable at login but catastrophic for an attacker doing bulk cracking.
Salting: a random value added to each password before hashing, stored alongside the hash. Without salt, identical passwords produce identical hashes, and attackers use precomputed rainbow tables. With a unique salt per user, those tables are useless.
If hashes can't be reversed, how are they "cracked"?
They aren't reversed — they're guessed.
An attacker takes a wordlist, hashes each entry with the same algorithm, and compares. Match found means the password is known. This is why password123 falls in milliseconds and a long random passphrase doesn't.
So "cracking a hash" is really "guessing the input fast enough."
See it yourself
Encode and decode Base64:
echo -n "hello world" | base64
echo "aGVsbG8gd29ybGQ=" | base64 -dNotice you needed no key. That's the entire point.
(The -n stops echo adding a newline. Without it you encode hello world plus an invisible line break, and get aGVsbG8gd29ybGQK instead — a classic source of "why doesn't my output match?")
Generate hashes:
echo -n "hello" | md5sum
echo -n "hello" | sha256sum
echo -n "hellp" | sha256sumCompare the last two — one letter different, completely different output.
Look at a real JWT. Log into almost any modern web app, open devtools, and find a token that looks like:
eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiYWRtaW4ifQ.signaturePaste the first two sections into a Base64 decoder. They decode. JWT payloads are encoded, not encrypted — meaning anyone holding a token can read what's inside it. This surprises a lot of developers, and it's why you must never put secrets in a JWT payload. You'll attack these properly in Stage 4.
How attackers abuse this
"Encrypted" data that's just encoded. An application stores dXNlcjphZG1pbg== and calls it encrypted. It decodes to user:admin in one command. This appears in real applications more often than it should.
Weak hashes on password dumps. A breached database using unsalted MD5 gets cracked almost entirely within hours using standard tools and wordlists. The same database using bcrypt might yield only the weakest handful of passwords.
Encoding as filter bypass. Security filters that check the raw input before decoding miss %3Cscript%3E and <script>. Double encoding defeats systems that decode once. Order of operations is everything.
Hash length extension attacks. Certain naive constructions using SHA-256 allow an attacker to append data to a signed message and produce a valid signature without knowing the secret. This is why HMAC exists.
Reading JWTs for recon. Even without breaking a token's signature, decoding its payload reveals user IDs, roles, expiry times and internal field names — a free map of the application's authorisation model.
Common mistakes
"Base64 is encryption." It is not, and this is the mistake that matters most. No key means no security. Ever.
"MD5 is fine for passwords, it's a hash." MD5 is broken and fast — the two worst properties for password storage. Use bcrypt or Argon2.
"Hashing is encryption with no key." No — they solve different problems. Encryption is for data you need to get back. Hashing is for data you never need to recover, only verify.
"Long hashes are stronger." Length alone doesn't determine strength. Algorithm design and speed matter more. A 128-character MD5-derived value is still MD5.
Check yourself
- You find
YWRtaW46cGFzc3dvcmQxMjM=in a config file. What is it, and what should you do? - Why is bcrypt better than SHA-256 for storing passwords, given both are considered secure hashes?
- A developer says "our JWT is safe, the user data inside is encrypted." What's wrong?
Answers
- It's Base64 — the trailing
=and character set give it away. Decoded, it readsadmin:password123. It is credentials stored with no protection at all. This is a serious finding, not a minor one. - SHA-256 is designed for speed, allowing billions of guesses per second on modern hardware. bcrypt is deliberately slow and has a tunable work factor, so each guess costs the attacker real time. For passwords, slow is the desired property.
- JWT payloads are Base64-encoded, not encrypted. Anyone with the token can decode and read the contents. The signature prevents modification, not reading. Secrets must never be placed in a JWT payload.
Your lab
Challenge 04 — Decode the encoded
You'll be given a chain of encoded values. Work through each layer to reach the flag. Identify the encoding at each step before decoding it.
→ Open Stage 0 labs
Summary in your language
தமிழ் சுருக்கம் (Tamil summary)
Encoding, Encryption, Hashing — மூன்றும் வேறு வேறு
1. Encoding (குறியீடு)
- நோக்கம்: தரவை ஒரு வடிவத்தில் இருந்து இன்னொரு வடிவத்திற்கு மாற்றுவது
- திரும்ப மாற்ற முடியுமா? ஆம் — யார் வேண்டுமானாலும், key தேவையில்லை
- பாதுகாப்பு: சுத்தமாக இல்லை
- உதாரணம்: Base64 —
hello→aGVsbG8=
2. Encryption (மறையாக்கம்)
- நோக்கம்: தரவை மறைப்பது
- திரும்ப மாற்ற முடியுமா? ஆம் — ஆனால் சரியான key இருந்தால் மட்டும்
- பாதுகாப்பு: அதிகம்
- உதாரணம்: AES, RSA, HTTPS
3. Hashing (ஹாஷிங்)
- நோக்கம்: password சேமிப்பது, தரவு மாறவில்லை என்று உறுதி செய்வது
- திரும்ப மாற்ற முடியுமா? இல்லை — ஒருபோதும் முடியாது
- password-க்கு பயன்படுத்த வேண்டியது: bcrypt அல்லது Argon2 (MD5 அல்ல)
மிக முக்கியமான விதி:
key இல்லை என்றால் அது encryption அல்ல. Base64-ஐ "encrypted" என்று சொல்வது தவறு — அதை யார் வேண்டுமானாலும் 2 விநாடியில் படிக்க முடியும்.
JWT பற்றி: JWT-யின் உள்ளே இருக்கும் தகவல் encode மட்டும் தான் செய்யப்பட்டிருக்கும், encrypt அல்ல. அதனால் ரகசியங்களை JWT-க்குள் வைக்கக் கூடாது.
हिंदी सारांश (Hindi summary)
Encoding, Encryption, Hashing — तीनों अलग हैं
1. Encoding
- मक़सद: data का format बदलना
- वापस बदल सकते हैं? हाँ — कोई भी, बिना key के
- सुरक्षा: बिल्कुल नहीं
- उदाहरण: Base64 —
hello→aGVsbG8=
2. Encryption
- मक़सद: data को छिपाना
- वापस बदल सकते हैं? हाँ — लेकिन सही key से ही
- सुरक्षा: बहुत अच्छी
- उदाहरण: AES, RSA, HTTPS
3. Hashing
- मक़सद: password सुरक्षित रखना, data की जाँच करना
- वापस बदल सकते हैं? नहीं — कभी नहीं
- password के लिए इस्तेमाल करें: bcrypt या Argon2 (MD5 नहीं)
सबसे ज़रूरी नियम:
अगर key नहीं है, तो वह encryption नहीं है। Base64 को "encrypted" कहना ग़लत है — कोई भी उसे 2 सेकंड में पढ़ सकता है।
JWT के बारे में: JWT के अंदर का data सिर्फ़ encode होता है, encrypt नहीं। इसलिए कोई भी उसे पढ़ सकता है — रहस्य कभी JWT में न रखें।
"Hash crack करना" का मतलब उसे उल्टा करना नहीं है — बल्कि लाखों passwords को hash करके मिलान करना है। इसीलिए password123 सेकंडों में टूट जाता है।
Want this summary in Malayalam, Telugu, Kannada or another language? Tell us — the most requested languages get added next.
What's next
Enough theory. Next lesson you open a tool you already have installed and start seeing things websites didn't mean to show you.
→ Lesson 7: Your browser's devtools — the free hacking tool