JWT Base64 Decode failed in Notepad++
Short answer:
To make the string decodable you have to make the number of characters in the encoded string an integer multiple of 4. Meaning you have to divide the number of characters by 4 and not get a remainder. In this particular case, you have 443 characters. Adding a =
at the end will make it decodable.
Long answer:
Base64 encoding uses something called padding. The number of characters in the output has to be an integer multiple of 4. If the actual output doesn't fulfill that requirement the encoding algorithm will add additional padding characters to the output. The padding character is usually =.
There are some examples on Wikipedia of how this works. You can also see this SO post.
There is a difference between "ordinary" base64url encoding, and the base64url encoding used with JWT: JWT skips the padding characters. They are simply not added. So any decoding algorithm for JWT has to take that fact into account.
Ordinary base64 decoders will not allow encoded strings without padding, as input (if padding was required). Most decoders have an assertion at the beginning of the decoding algorithm where they check the length of the input string and check that the length % 4 = 0. You can see that from the error message
Length of selected text (not including EOL) to be decoded is invalid. It should be mod 4.
The length is wrong because the padding characters are missing.
So using decoders that handle padless strings is the way to go. Andre already linked one site. Here is another.
JWT are encoded using "base64url" which uses a URL-safe alphabet.
The "base64url" encoding is the Base 64 encoding where URL-reserved characters are replaced (e.g. -
replaces +
and _
replaces /
) and the padding characters are removed.
The token above is not the same in the Azure B2C doc indicated and it seems invalid. Unless this question is about Notepad++, I'd recommend using a site like https://jwt.ms to decode tokens. jwt.ms helps you not only decode the token but also understand what each one of claims means.