01 / 20

Encryption, Hashing
& Encoding

Understand the three pillars of data transformation in cybersecurity: when to use each, how they differ, and why confusing them creates vulnerabilities.

Cyber Security

Why Data Transformation Matters

Every time you log in, send a message, or store a password, your data undergoes a transformation. The wrong transformation choice can expose sensitive information or break an application entirely.

Confidentiality
Encryption keeps data secret from unauthorized eyes
Integrity
Hashing verifies data has not been tampered with
Compatibility
Encoding ensures data travels safely between systems

What is Encoding?

Encoding transforms data into a different format using a publicly known scheme. It is not a security mechanism: anyone who knows the scheme can reverse it. Its purpose is data compatibility and transport.

Hello! Base64 SGVsbG8h Decode Hello! Fully reversible: no key required

What is Hashing?

Hashing is a one-way function that converts any input into a fixed-length digest. It is not reversible: you cannot recover the original data from the hash. Its purpose is integrity verification and password storage.

password SHA-256 Hash Function 5e884898da28... Fixed 256-bit ✕ Cannot reverse No decryption key exists

What is Encryption?

Encryption transforms data into an unreadable format using a key. Unlike hashing, it is reversible: anyone with the correct key can decrypt the data. Its purpose is confidentiality.

Plaintext Encrypt + Key KEY a3f2b8c1... Ciphertext ✓ Reversible with correct key

The Core Rule of Data Transformation

Encoding Reversible, no key Encryption Reversible, with key Hashing One-way, no reverse Compatibility Confidentiality Integrity Base64, URL, UTF-8 AES, RSA, ChaCha20 SHA-256, bcrypt, MD5 ✕ Not security ✓ Security tool ✓ Security tool

Key Distinction: Reversibility

Encoding No key ✓ Fully reversible Encryption With key ✓ Reversible (key required) Hashing One-way ✕ Not reversible

Symmetric vs Asymmetric Encryption

Symmetric
One shared key for both encryption and decryption. Fast, efficient, used for bulk data. Examples: AES-256, ChaCha20.
Asymmetric
Public key encrypts, private key decrypts. Slower, but solves the key-exchange problem. Examples: RSA, ECC.

Properties of a Secure Hash

1
Deterministic: The same input always produces the same hash output.
2
Fixed-length output: Regardless of input size, the digest length is constant (e.g., SHA-256 always produces 256 bits).
3
Avalanche effect: A single-bit change in input radically changes the output hash.
4
Collision resistant: It should be computationally infeasible to find two different inputs that produce the same hash.
5
Pre-image resistant: Given a hash, you cannot feasibly determine the original input.

How to Choose the Right Technique

1
Ask: "Do I need to recover the original data?" If no, use hashing. If yes, continue.
2
Ask: "Does it need to be kept secret?" If yes, use encryption. If no, continue.
3
Ask: "Am I just converting data format?" If yes, use encoding (e.g., Base64 for email attachments).
4
Validate: Never use encoding for security. Never try to "decrypt" a hash. Always salt your hashes for passwords.

Example: Password Storage

A user signs up with password "MyP@ss123". How should the application store this password?

MyP@ss123 + Random Salt bcrypt Hash + Salt $2b$12$x9Kz... Stored in DB ✕ Store plaintext ✕ Use Base64 ✕ Encrypt with AES ✓ Hash with bcrypt ✓ Add random salt ✓ Use slow hash function

Example: Secure Messaging

Alice wants to send a confidential message to Bob over the internet. Which technique should she use?

A Alice Secret Msg AES-256 Encrypt Shared Key a3f2b8... Internet B Bob ✕ Attacker sees only ciphertext

Example: File Integrity Verification

You download an installer from the internet. The website provides a SHA-256 checksum. How do you verify the file has not been tampered with?

1
Download the file and note the provided checksum from the website.
2
Hash the downloaded file locally using the same algorithm (SHA-256).
3
Compare your computed hash with the website's checksum.
4
If they match, the file is intact. If they differ, the file was modified in transit.

Why Salting Matters for Hashes

Without a salt, identical passwords produce identical hashes. Attackers use precomputed rainbow tables to look up common hashes. A salt is random data appended to each password before hashing, making every stored hash unique.

✕ Without Salt password 5e884898da... password 5e884898da... Same hash! Vulnerable ✓ With Salt password + salt_a7x b2c9f1... password + salt_k3m d7e4a3... Different hashes! Safe

Common Mistakes to Avoid

✕ Base64 for Security
Using Base64 to "hide" passwords or tokens. Base64 is encoding, not encryption: anyone can decode it instantly.
✕ Encrypting Passwords
If the encryption key leaks, all passwords are exposed. Hash passwords instead: no key to steal.
✕ Unsalted Hashes
Hashing without salt means identical passwords share the same hash, enabling rainbow table attacks.
✕ Using MD5 or SHA-1
Both are considered broken for security. MD5 has known collision attacks. Use SHA-256 or bcrypt instead.
✕ "Decrypting" a Hash
Hashes are one-way by design. You cannot decrypt a hash: you can only verify by hashing the same input and comparing.

Comparison Summary Table

Property Encoding Encryption Hashing
Purpose Data format compatibility Confidentiality Integrity / verification
Reversible? Yes, always Yes, with key No
Key required? No Yes No
Output length Variable Variable Fixed
Security tool? ✕ No ✓ Yes ✓ Yes
Examples Base64, URL, UTF-8 AES, RSA, ChaCha20 SHA-256, bcrypt, Argon2

Question 1 of 5

A web application stores user passwords by converting them to Base64. What is the primary security issue with this approach?

Question 2 of 5

Which of the following best describes the avalanche effect in hashing?

Question 3 of 5

Alice needs to send a confidential document to Bob, and Bob must be able to read the original content. Which technique should Alice use?

Question 4 of 5

A company stores password hashes without salting. What specific attack does this make feasible?

Question 5 of 5

You download software and want to verify the file was not corrupted or tampered with during download. The developer provides a SHA-256 checksum. What should you do?