Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Parase with claims failed. signature is invalid #272

Closed
Cheney-Su opened this issue Jun 19, 2018 · 6 comments
Closed

Parase with claims failed. signature is invalid #272

Cheney-Su opened this issue Jun 19, 2018 · 6 comments

Comments

@Cheney-Su
Copy link

Why i new a token by java,and i parse it by golang,then told me ‘parase with claims failed. signature is invalid’?I fount java string to bytes use us-ascii ,but golang use RFC 4648,Is this a problem?How can I solve it?

@dgrijalva
Copy link
Owner

The character set used by tokens should be the same in most US based encodings. I'd use UTF8 where you can, but this is unlikely to be why your token didn't verify. It's difficult to be helpful without more information, though.

@dgrijalva
Copy link
Owner

I'm going to close this ticket. If you'd like to share an example, I might be able to be more helpful. Please make sure you don't use any real secrets when creating examples.

@Cheney-Su
Copy link
Author

Cheney-Su commented Jun 20, 2018

For example,the key is ’whatthefuck‘,and The token I got was ‘eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYmYiOjE1Mjk0NTk4OTU1MDAsImlzcyI6ImRvdWJsZXMiLCJleHAiOjE1MzA0NTk4OTY1MDB9.1EADHewsDi0rX4nNDZ2WEwVrGn_Nfn0m954b9OoiXuY’ through java(jar is io.jsonwebtoken.jjwt 0.9.0),but this token cannot be parsed through go。The Error message is parase with claims failed. signature is invalid。

@Cheney-Su
Copy link
Author

I have solved this problem!Convert key from string to byte requires base64.URLEncoding.DecodeString(key) instead of []byte(key), and then it can be resolved successfully.
Thanks!

@marmiha
Copy link

marmiha commented Nov 10, 2020

I have solved this problem!Convert key from string to byte requires base64.URLEncoding.DecodeString(key) instead of []byte(key), and then it can be resolved successfully.
Thanks!

This worked for me too. Had to do it both on the encoding and decoding side.

@jaychang9
Copy link

        jwt_token_str := "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYmYiOjE1Mjk0NTk4OTU1MDAsImlzcyI6ImRvdWJsZXMiLCJleHAiOjE1MzA0NTk4OTY1MDB9.1EADHewsDi0rX4nNDZ2WEwVrGn_Nfn0m954b9OoiXuY"
	claims := jwt.MapClaims{}
	token, err := jwt.ParseWithClaims(jwt_token_str, claims, func(token *jwt.Token) (interface{}, error) {
		return base64.URLEncoding.DecodeString("whatthefuck")
	})

error is
"illegal base64 data at input byte 8"
why ?

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

No branches or pull requests

4 participants