# Need Help With Decoding JWT in HS256

**URL:** <https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238>\
**Category:** Get Help\
**Tags:** other, missing-category\
**Created:** [December 12, 2022, 9:00am UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238 "2022-12-12T09:00:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![renekthrope](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/renekthrope/32/33935_2.png) [@renekthrope](https://community.auth0.com/u/renekthrope)\
**Post date:** [December 12, 2022, 9:00am UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238/1 "2022-12-12T09:00:49Z")

</div>

I don’t know what to put here, in this line of code:  
#include \<jwt-cpp/jwt.h\>  
auto decoded = jwt.decode(what to put here)  
I get errors when I try.

 ![jwtask](https://global.discourse-cdn.com/auth0/original/3X/7/2/72004428dca99474f2cc36fbe56c0bb2ceb6e30c.png)

I am trying to decode a JWT with HS256 using a specific key.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 12, 2022, 3:58pm UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238/3 "2022-12-12T15:58:28Z")

</div>

Hi @renekthrope,

It would be helpful to know what language and SDKs you are using. 😄

---

<div class="post-metadata">

**Author:** ![renekthrope](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/renekthrope/32/33935_2.png) [@renekthrope](https://community.auth0.com/u/renekthrope)\
**Post date:** [December 13, 2022, 4:44am UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238/4 "2022-12-13T04:44:43Z")

</div>

My apologies, here it is:  
Language: C++  
SDK/s: git clone [GitHub - Thalhammer/jwt-cpp: A header only library for creating and validating json web tokens in c++](https://github.com/Thalhammer/jwt-cpp.git)

Thanks for letting me know.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 13, 2022, 3:35pm UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238/5 "2022-12-13T15:35:05Z")

</div>

Thanks for the added info.

With that library, the `jwt.decode()` function appears to take a base64 encoded JWT (a string), and decodes it. It’s important to note, **that function does not verify the token.**

To verify the token you need to pass your secret, claims, and the decoded token.

Here is their example:

```auto
auto verifier = jwt::verify()
    .allow_algorithm(jwt::algorithm::hs256{ "secret" })
    .with_issuer("auth0");

verifier.verify(decoded_token);

```

Does that help?

---

<div class="post-metadata">

**Author:** ![renekthrope](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/renekthrope/32/33935_2.png) [@renekthrope](https://community.auth0.com/u/renekthrope)\
**Post date:** [December 15, 2022, 6:27am UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238/6 "2022-12-15T06:27:19Z")

</div>

Hey,

Thanks for your reply. What I wanted is to decode the JWT token that is saved in a STRING, that is encrypted by HS256. I am not looking to encode it.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 15, 2022, 2:20pm UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238/7 "2022-12-15T14:20:00Z")

</div>

Hi @renekthrope,

JWTs are usually encoded and signed, **not encrypted**.

The secret is used to verify the signature and is not needed to decode the JWT.

You may want to do some reading to understand JWTs and how they work before using them. This is a good place to start:

> **[JWT.IO - JSON Web Tokens Introduction](https://jwt.io/introduction)**
>
> Learn about JSON Web Tokens, what are they, how they work, when and why you should use them.

---

<div class="post-metadata">

**Author:** ![renekthrope](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/renekthrope/32/33935_2.png) [@renekthrope](https://community.auth0.com/u/renekthrope)\
**Post date:** [December 16, 2022, 8:07pm UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238/8 "2022-12-16T20:07:16Z")

</div>

Hey,

Ohhh now I understand, I thought it was encrpyted and a secret key was needed, the secret key was confusing me. Thank you, I am just writing this so who needs it can see it.

**This is to install library for linux ubuntu:**

> /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> //JWT and Git STEP BY STEP  
> sudo apt-get install libssl-dev
> 
> sudo apt-get install git-all
> 
> //Install libcrypto+±dev and cmake packages  
> sudo apt install libcrypto+±dev cmake
> 
> //GIT  
> git clone [GitHub - Thalhammer/jwt-cpp: A header only library for creating and validating json web tokens in c++](https://github.com/Thalhammer/jwt-cpp.git)
> 
> //Go to jwt-cpp folder  
> cd jwt-cpp
> 
> //Create a build directory and go to it  
> mkdir build && cd build
> 
> //Run cmake  
> cmake …
> 
> //Compile and install jwt-cpp library  
> make && sudo make install
> 
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

**To decode JWT HS256:**

> #include \<jwt-cpp/jwt.h\>
> 
> auto test = jwt::decode(jwtString);  
> std::string result = test.get\_payload();  
> std::cout \<\< result \<\< std::endl;

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 30, 2022, 8:08pm UTC](https://community.auth0.com/t/need-help-with-decoding-jwt-in-hs256/96238/9 "2022-12-30T20:08:12Z")

</div>

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