Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why header and payload in the JWT token always starts with eyJ

Tags:

jwt

I am using JWT token to authorize my APIs, during implementation I found header and payload in token always start with eyJ. What does this indicate?

like image 370
Suresh Prajapati Avatar asked Mar 27 '18 15:03

Suresh Prajapati


People also ask

Why does JWT start with EYJ?

In fact, they might look like random strings of characters, but they're actually base64 encoded JSON objects (tip: you may notice that all JWTs start with an “ey” … that's because “ey” is the start of any base64 encoded string that begins with the {" character sequence (… as all JSON object do).

What is header and payload in JWT?

Header. The header typically consists of two parts: the type of the token, which is JWT, and the algorithm that is used, such as HMAC SHA256 or RSA SHA256. It is Base64Url encoded to form the first part of the JWT. Payload. The payload contains the claims.

What is the correct format of JWT token?

JWT Structure. A JWS (the most common type of JWT) contains three parts separated by a dot ( . ). The first two parts (the "header" and "payload") are Base64-URL encoded JSON, and the third is a cryptographic signature.


1 Answers

JWTs consist of base64url encoded JSON, and a JSON structure just starts with {"..., which becomes ey...when encoded with a base64 encoder. The JWT header starts with {"alg":..., which then becomes eyJ...

You can try on this online encoder and enter {"alg" and click on encode. The result will be eyJhbGciPSA=

like image 138
jps Avatar answered Oct 10 '22 21:10

jps