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 )