Skip to main content

8 posts tagged with "OpenSSL"

The OpenSSL Command Line Tool for Encoding, Hashing, Signing and Keys

View All Tags

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.

How to Create an HMAC-SHA256 Signature in the Terminal

· 8 min read
Jagdish Kumawat
Founder @ Dewiride

An HMAC is a signature made with a secret key. Anyone with the same key can make the same signature, and anyone without it can't. HMAC-SHA256 signs JSON Web Tokens that use HS256, and many webhooks use it to prove where a request came from. This guide creates one in the terminal and checks it against the official test value.

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.