Course contentsShow
← Web Development
Lesson 1580 of 2,98229. Web Authentication PatternsFree lesson

Encoding vs Encryption: JWT Security Basics

Understanding that JWTs are base64-encoded but not encrypted, and what this means for sensitive data.

Encoding vs Encryption: JWT Security Basics

You'll learn why JWTs are readable by anyone and what that means for storing sensitive information.

JWTs Are NOT Secret

Here's a critical misconception: many developers assume that because JWTs look like encrypted gibberish, their contents are secure. They're not. JWTs use base64url encoding, which is simply a way to represent binary data as text—it's completely reversible by anyone.

Think of encoding like writing a message in pig Latin. It looks different, but anyone who knows the pattern can read it instantly. Encryption, on the other hand, is like locking that message in a safe—you need the key to access it.

What This Means in Practice

When you look at a JWT like this:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEyMzQ1LCJlbWFpbCI6InVzZXJAZXhhbXBsZS5jb20ifQ.signature

Anyone can decode the middle section (the payload) and read {"userId":12345,"email":"user@example.com"}. No hacking required—just paste it into any JWT decoder online.

What IS Protected?

The signature (third part of the JWT) ensures that the token hasn't been tampered with. Someone can read your JWT, but they can't modify it without invalidating the signature. The server verifies this signature using its secret key.

Practical Security Rules

  • Never put passwords, credit card numbers, or sensitive secrets in a JWT payload
  • Store user IDs, roles, and non-sensitive metadata only
  • Anyone who intercepts the token can read it—this is why HTTPS is mandatory
  • The signature protects integrity (no tampering), not confidentiality (no peeking)

Key Takeaway: JWTs are base64-encoded (readable by anyone) but cryptographically signed (tamper-proof). Never store sensitive data in the payload—treat JWTs as public information protected only by HTTPS in transit.