我正在使用jjwt为我的应用程序创建JWT,在我将Java版本从1.8升级到OpenJDK 11之前,它一直运行良好。
现在,每当我使用下面的代码片段生成JDK时,它都会引发Throwable错误,而且不是在本地环境中,而是在UAT服务器中。
可抛出错误(单行):
io.jsonwebtoken.SignatureAlgorithm.getMinKeyLength()
我的代码段
/**
* {@inheritDoc}
*/
public JWTResponse getJWT(UserRoleObject userRoleObject) {
Key key = Keys.hmacShaKeyFor(getHS256SecretBytes());
String jws = Jwts.builder()
.setIssuer(jwtIssuer) // Issuer of the JWT
.setSubject(jwtSubject) // Purpose of this JWT
.addClaims(getClaims(userRoleObject)) // Claims containing User Information
.setIssuedAt(PartnerPortalUtil.getDateInGMT()) // When this token is being issued
.setExpiration(DateUtils.addHours(PartnerPortalUtil.getDateInGMT(), tokenExpiryHours)) // When this token will be expired
.signWith(key)
//.signWith(SignatureAlgorithm.HS256, getHS256SecretBytes()) // How this token is being signed
.compact();
return new JWTResponse(jws);
}
和我的getH256SecretBytes方法看起来像这样:
/**
* Method to get the secret key in Bytes which will be used to sign the JWT./
*
* @return Byte array representation of the secret key being used.
*/
private byte[] getHS256SecretBytes() {
return TextCodec.BASE64.decode(secrets.get(SignatureAlgorithm.HS256.getValue()));
}