As the title says, I'm trying to generate a JWT using jjwt in my spring boot starter web app and I hit this exception when I call compact() on the builder to actually return the JWT. More specifically:
class io.jsonwebtoken.impl.lang.OptionalMethodInvoker cannot access class sun.security.util.KeyUtil (in module java.base) because module java.base does not export sun.security.util to unnamed module
I've just been following the guide on the jjwt GitHub page: https://github.com/jwtk/jjwt
(Not sure if this is too relevant) but I'm using JDK corretto-20 with gradle 8.3 on Intellij IDEA. My jjwt dependencies in my build.gradle.kts:
implementation("io.jsonwebtoken:jjwt-api:0.12.0")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.0")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.0")
and the basic authenticator I've made so far which tries to generate the JWT:
package myproject.utility;
import io.jsonwebtoken.Jwts;
import myproject.model.User;
import javax.crypto.SecretKey;
public class Authenticator {
private final static SecretKey secretKey = Jwts.SIG.HS256.key().build();
public static String generateJwt(User user) {
return Jwts.builder().claim("username", user.getUsername()).signWith(Authenticator.secretKey).compact();
}
}
To pinpoint which bit was throwing the error I added each part of the JWT build process one at a time and it fails after calling compact() at the final step
The error feels pretty self-explanatory but I have no idea how to fix this. Any help would be appreciated