Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With Base64 decode i can read the hashed content #306

Closed
alessandroarioli opened this issue Apr 17, 2019 · 2 comments
Closed

With Base64 decode i can read the hashed content #306

alessandroarioli opened this issue Apr 17, 2019 · 2 comments

Comments

@alessandroarioli
Copy link

alessandroarioli commented Apr 17, 2019

I have this strange behaviour:

JWT.encode({name: 'alessandro'}, 'itw', 'HS256')
 => "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiYWxlc3NhbmRybyJ9.h1ZMLLxLKpL2wfEd6k2ZIuAzh_YKlCuFkY9IOZeE2qE" 
2.3.1 :021 > Base64.decode64("eyJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiYWxlc3NhbmRybyJ9.h1ZMLLxLKpL2wfEd6k2ZIuAzh_YKlCuFkY9IOZeE2qE")
 => "{\"alg\":\"HS256\"}{\"name\":\"alessandro\"}\x87VL,\xBCK*\x92\xF6\xC1\xF1\x1D\xEAM\x99\"\xE03\x85\x82\xA5\n\xE1dc\xD2\x0Ee\xE16\xA8"

i can see the plain payload content.
Also using the RS256 with Open SSL key:

2.3.1 :022 > JWT.encode({name: "alessandro"}, OpenSSL::PKey::RSA.generate(2048), 'RS256') => "eyJhbGciOiJSUzI1NiJ9.eyJuYW1lIjoiYWxlc3NhbmRybyJ9.JZ4EaZ7x-n5UXe67saFS_nOJsSZC4tOUqytC3SDnSsNeYqNO6uamrTY_ZHIBA9kNH3sUasMunl_rLAh8Rx421s8u2MkedgcjvlaWGroKIjd3bQBIJ9LjX40FT9m5ClMNcurcha-QzTPVux_-rE8ytUeFd01dD3iFBHgzc4O7wdWnuU63T56xhRjfhGO74jg5HR0aQCt2KMk3leycQ12f36hQe-RrL3bYlSz3V-8ZQ8VtXwsIFjbWEaWCbmQgjExvQzIrFDzFOUuqFDnVhv1LFc3NW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5\x1F\xB6+\xB4\x8A$\x02f<\x19s^\xDD\x93\xF9\x83tT\xA4\x87#\xB2\xD8\xD9\xD8\x8DwL\xAA\xFC^\xD3q\xA2\xBF\x14"

It's looks like is appending the hash to the payload ... I'm doing something wrong?

@excpt
Copy link
Member

excpt commented Apr 17, 2019

That behavior you're seeing is correct. JWT only signs the payload.
The algorithms you're selecting for the normal JWT.encode are only for the signature generation and verification.

If you want to encrypt your payload you have to dive into JWE here: https://github.com/jwt/ruby-jwe

@alessandroarioli
Copy link
Author

Ok, i thought that the library did the entire job. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants