Verifying JWT Signature

hi folks,

I am trying to understand how the JWT Signature verification works and i have read this page under the “Check signature” section. The documentation states that:

" 1. Take the original Base64url-encoded Header and original Base64url-encoded Payload segments (Base64url-encoded Header + “.” + Base64url-encoded Payload), and hash them with SHA-256.
2. Encrypt using either HMAC or RSA (depending on your selected signing algorithm) and the appropriate key."

This is surely a mistake or have i misunderstood things? During signature verification there is no encryption necessary when dealing with RSA keys. What you have a public key to decrypt the hash and verify that the current hash and the original hash are equal.

This document is confusing me and need help with clarity.

Hi there,

I wont claim to be an expert on RSA or HMAC, as I typically use a library for JWT signing and verification, but I think I can help provide some resources that can provide clarity.

The Wikipedia doc on RSA signing helps to explain what is happening to the hash after step 1., and how it is similar/is encryption:

Suppose Alice wishes to send a signed message to Bob. She can use her own private key to do so. She produces a hash value of the message, raises it to the power of d (modulo n ) (as she does when decrypting a message), and attaches it as a “signature” to the message. When Bob receives the signed message, he uses the same hash algorithm in conjunction with Alice’s public key. He raises the signature to the power of e (modulo n ) (as he does when encrypting a message), and compares the resulting hash value with the message’s hash value. If the two agree, he knows that the author of the message was in possession of Alice’s private key, and that the message has not been tampered with since being sent.

Does that help?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.