Encoding, Encryption and Hashing
Chapters and transcript
Encoding, Encryption, Hashing A developer in this office puts a secret API key into the app config. He says it is encrypted, so it is safe. An attacker finds the config, and reads the key in one second. What went wrong? The developer used encoding, not encryption. Today you will learn the difference between encoding, encryption and hashing.
The short version Here is the short version. Encoding changes the format of data. It needs no key, and anyone can reverse it. Base64 is an example. Encryption keeps data secret. It needs a key, and only someone with the key can reverse it, like AES. Hashing creates a fingerprint. It cannot be reversed at all, like SHA-256.
Encoding in action Let me show you on the laptop. I encode the text Hello SECUREK in Base64. The result is letters and numbers, ending with equals signs. It looks secret, but it is not. I decode it, with no key, and the original text comes straight back. Now the key from our developer: decoded in one second.
Encoding So when is encoding the right tool? Use it to change the format of data, so it can be sent or stored safely, for example in a web address or an email. But never use encoding to hide a password or an API key. There is no key and no secret. Attackers decode it instantly. If something must stay secret, encrypt it.
Encryption Encryption scrambles data with a key. There are two kinds. Symmetric encryption uses one key to lock and unlock. It is fast, and is used for files, disks and network traffic. AES is the standard. Asymmetric, or public-key, encryption uses a pair of keys: a public key you can share with anyone, and a private key you keep secret.
Encryption Here is symmetric encryption at work. Sara locks a file with a shared key, and sends it across public Wi-Fi. Someone nearby captures it, but without the key they only see scrambled data. Bilal has the same key, so the file opens for him. The weak point is the key itself, so it must stay secret.
Public-key encryption Now public-key encryption. You share your public key with anyone. A sender locks a message with it. An attacker on the way catches the message, but the public key cannot unlock it. Only your private key can. HTTPS uses this idea to safely agree on a key with websites you have never visited before.
Quick check Quick check. A developer is building a login page and must store user passwords. The website only needs to check them, never read them back. Which one should the developer use? Take a moment, then choose.
Hashing As you learned in the last lesson, hashing is a one-way fingerprint. It cannot be reversed. It is used to store passwords safely. It is used to check that a file has not been changed: you hash the file you downloaded, and compare it with the official hash. And it is used to detect duplicate data.
JWT login tokens Here is a common example that mixes these ideas. Many websites keep you logged in with a JSON Web Token, or JWT. It has three parts separated by dots. The header and payload are only Base64URL encoded, so anyone can read them. The signature uses a secret key, so nobody can change the token without the server noticing. So a JWT is signed, not encrypted.
JWT login tokens Let me prove it. I take the payload, the middle part of a practice token, and decode it. No key is needed. The data inside is plain to read: the user name and the role. Anyone who gets the token can do this, so developers should never put passwords or other secrets inside a JWT.
Putting it together Let us put it together. To choose the right tool, ask what you need. Sending data in a web address or email? Use encoding. Keeping data secret, but readable later? Use encryption. Checking passwords or detecting changes? Use hashing. And remember: encoding is never protection. Now read the lesson below, then try the labs and find out what a developer is really hiding.
These three words sound similar, and many developers confuse them. Mixing them up leads to real security mistakes.
The short version
| Purpose | Needs a key? | Can be reversed? | Example | |
|---|---|---|---|---|
| Encoding | Change the format of data | No | Yes, by anyone | Base64, URL encoding |
| Encryption | Keep data secret | Yes | Yes, with the key | AES, RSA |
| Hashing | Create a fingerprint | No | No | SHA-256, bcrypt |
Encoding: not for secrets
Encoding changes data into a different format so it can be stored or sent safely. Base64 is the most common example. It turns any data into letters, numbers, + and /, often ending with =:
Hello SECUREK → SGVsbG8gU0VDVVJFSw==
There is no key and no secret. Anyone can decode it in a second.
A common mistake: a developer "hides" a password or API key in Base64 and believes it is encrypted. Attackers decode it instantly.
Encryption: for secrets you need to read again
Encryption scrambles data with a key. Only someone with the right key can turn it back into readable data.
Symmetric encryption uses one key for both locking and unlocking. It is fast, and is used for files, disks and network traffic. AES is the standard algorithm.
Asymmetric (public-key) encryption uses a pair of keys:
- A public key that you can share with anyone
- A private key that you keep secret
What is locked with the public key can only be unlocked with the private key. HTTPS uses this to safely agree on a key with websites you have never visited before.
Hashing: a one-way fingerprint
As you learned in the previous lesson, hashing cannot be reversed. It is used to:
- Store passwords safely
- Check that a file has not been changed (compare its hash with the official one)
- Detect duplicate data
A common example: JWT login tokens
Many websites keep you logged in with a JSON Web Token (JWT). It looks like random text in three parts separated by dots:
header.payload.signature
The header and payload are only Base64URL encoded, so anyone can decode and read them. The signature uses a secret key, so nobody can change the token without the server noticing. In other words, a JWT is signed, not encrypted. Developers should never put secrets inside one.
Which one should you use?
- Sending data in a URL or email? Encoding
- Keeping data secret but readable later? Encryption
- Checking passwords or detecting changes? Hashing
In the labs, a developer claims a value is "encrypted", and you will read the inside of a login token. Find out what they are really hiding.
HANDS-ON LAB
Decode the Message
A developer says this config value is "encrypted". Is it?
HANDS-ON LAB
Read the Token
Login tokens look scrambled. Are they really secret?
Check your understanding
Answer every question correctly to complete this lesson. If you miss one, try the quiz again.
1. Which one can anyone reverse without a key?
2. You need to store data that you must read back later, but keep it secret. What do you use?
3. In public-key encryption, which key do you share with others?
Locked: answer every quiz question above correctly to complete this lesson.
Spotted a mistake or something unclear? Report a mistake