You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue record the problems in programming, and the solutions that I used.
In security/jwt/JwtUtils.java .signWith(SignatureAlgorithm.HS512, jwtSecret) will use JwtBuilder signWith(SignatureAlgorithm alg, String base64EncodedSecretKey) throws InvalidKeyException; method.
This method will use base64 decoder to decode base64EncodedSecretKey, so the length of jwtSecret in application.properties could not be too short, if the length of secret string is not enough, the program may throw the following exception:
io.jsonwebtoken.security.WeakKeyException: The signing key's size is xxx bits which is not secure enough for the HS512 algorithm.
The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HS512 MUST have a size >= 512 bits (the key size must be greater than or equal to the hash output size).
Consider using the io.jsonwebtoken.security.Keys class's 'secretKeyFor(SignatureAlgorithm.HS512)' method to create a key guaranteed to be secure enough for HS512.
See https://tools.ietf
To solve this exception, I should provide long enough secret string, futher more, I'd like to use origin secret string instead of Base64 encoded string, so I use JwtBuilder signWith(SignatureAlgorithm alg, byte[] secretKey) throws InvalidKeyException; method, and the code in JwtUtils.java like this:
and in application.properties file, jwtSecret contains at least 64 chars.
I noticed that signWith(SignatureAlgorithm alg, byte[] secretKey), signWith(SignatureAlgorithm alg, String base64EncodedSecretKey) and Jwts.parser() are deprecated in jjwt 0.11.5, so I use new methods, the code in JwtUtils.java like this:
This issue record the problems in programming, and the solutions that I used.
In security/jwt/JwtUtils.java
.signWith(SignatureAlgorithm.HS512, jwtSecret)
will useJwtBuilder signWith(SignatureAlgorithm alg, String base64EncodedSecretKey) throws InvalidKeyException;
method.This method will use base64 decoder to decode base64EncodedSecretKey, so the length of jwtSecret in
application.properties
could not be too short, if the length of secret string is not enough, the program may throw the following exception:To solve this exception, I should provide long enough secret string, futher more, I'd like to use origin secret string instead of Base64 encoded string, so I use
JwtBuilder signWith(SignatureAlgorithm alg, byte[] secretKey) throws InvalidKeyException;
method, and the code in JwtUtils.java like this:and in application.properties file, jwtSecret contains at least 64 chars.
I noticed that
signWith(SignatureAlgorithm alg, byte[] secretKey)
,signWith(SignatureAlgorithm alg, String base64EncodedSecretKey)
andJwts.parser()
are deprecated in jjwt 0.11.5, so I use new methods, the code in JwtUtils.java like this:Technology
PS: Thanks to the author for the great spring boot examples.
The text was updated successfully, but these errors were encountered: