Hackforge Academy

Category: java

wht is jwt

Published on 30 Mar 2026

Explanation

JWT (JSON Web Token) is a secure way to transmit information between client and server as a JSON object πŸ”. It is commonly used for authentication and authorization in web applications.

Code:

Example JWT Token:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJ1c2VySWQiOjEyMywibmFtZSI6IlByYXZlZW4ifQ.
SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Explanation

A JWT token has three main parts: Header, Payload, and Signature 🧩. These parts are separated by dots (.) and encoded using Base64.

Code:

Structure:
Header.Payload.Signature

Explanation

The Header section contains information about the token type and signing algorithm used (like HS256) βš™οΈ.

Code:

{
  "alg": "HS256",
  "typ": "JWT"
}

Explanation

The Payload section contains user-related data such as user ID, role, or permissions πŸ“„. This data is called claims.

Code:

{
  "userId": 101,
  "role": "student",
  "exp": 1716239022
}

Explanation

The Signature ensures the token is secure and not modified during transmission πŸ›‘οΈ. It is created using the header, payload, and a secret key.

Code:

HMACSHA256(
  base64UrlEncode(header) + "." + 
base64UrlEncode(payload),
  secret_key
)

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community