-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
There is an overloaded mehtod - JwtBuilder#setSigningKey. It may accept base64 encoded String, or it may accept byte[]
Here is the implementation in your source:
@Override
public JwtParser setSigningKey(byte[] key) {
Assert.notEmpty(key, "signing key cannot be null or empty.");
this.keyBytes = key;
return this;
}
@Override
public JwtParser setSigningKey(String base64EncodedKeyBytes) {
Assert.hasText(base64EncodedKeyBytes, "signing key cannot be null or empty.");
this.keyBytes = TextCodec.BASE64.decode(base64EncodedKeyBytes);
return this;
}
It seems to me, that in 2nd method, if base64 encoded key is decoded before being set to keyBytes --> keyBytes field is a plain bytes key, i.e. not byte of base64 encoded key. However, it seems not be the case with setSigningKey(byte[] key) method.
Problem:
-
When I pass just bytes in the UTF-8 unicode encoding to method
setSigningKey(byte[] key), then the library complains about signature. -
However, if I pass bytes of base64 encoded key into
setSigningKey(byte[] key), then the key parsed fine. The is clear contriversion in the API, becausesetSigningKey(byte[] key)works with base64 encoded bytes, whilesetSigningKey(String base64EncodedKeyBytes)before setting the key decodes the base64 string. That's really wired.
I have created the repository to demostrate this behavior: https://github.com/Mikhail2048/jjwt-base64-bug-reporduction
There are 2 test cases, you can clone and run them. Jjwt version is 0.9.1 - latest I have found publically.