我读了公钥/私钥,这样你就可以
验证用户JWT令牌。
但是,他们使用私钥/公钥的示例需要私钥验证,这似乎是奇怪的->。
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
RSAPublicKey publicKey = //Get the key instance
RSAPrivateKey privateKey = //Get the key instance
try {
Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);
JWTVerifier verifier = JWT.require(algorithm)
.withIssuer("auth0")
.build(); //Reusable verifier instance
DecodedJWT jwt = verifier.verify(token);
} catch (JWTVerificationException exception){
//Invalid signature/claims
}没有办法仅用公钥进行验证吗?
发布于 2022-04-25 15:31:54
在这条线上:
Algorithm algorithm = Algorithm.RSA256(publicKey, privateKey);将privateKey作为null传递。私钥是用来签名的。
Algorithm algorithm = Algorithm.RSA256(publicKey, null);https://stackoverflow.com/questions/71142269
复制相似问题