Skip to main content

7 posts tagged with "JWT"

JSON Web Tokens (JWT), How They Are Built, Signed, Read and Checked

View All Tags

Fixed: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

I passed one part of a JSON Web Token (JWT) to PowerShell's [Convert]::FromBase64String, and it refused with The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. The part was base64url, which differs from base64 in two ways, and fixing only one of them isn't enough.

How to Generate a Secret Key for HS256 JWTs in the Terminal

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A JSON Web Token signed with HS256 is only as safe as its secret key. Whoever has the key can make tokens your app will accept. A short or guessable key can be found by testing guesses against any token signed with it, with no need to contact your server. One command gives you a key that's long and random enough.

Fixed: openssl base64 -d Cuts Off a JWT Payload or Prints Nothing

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

I decoded the payload of a JSON Web Token (JWT) with openssl base64 -d, and OpenSSL 3.5 printed only half of the JSON. The openssl built into macOS did better, but it still dropped the last two characters. Neither printed an error, and both ended with exit status 0. The cause is the = padding that every JWT leaves out, and putting it back fixes both.