Java实现基于token认证( 二 )


.sign(algorithm);
return token;
} catch (Exception e) {
return null;
}
}
public static String verify(String token) {
try {
Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
JWTVerifier verifier = JWT.require(algorithm).build();
DecodedJWT jwt = verifier.verify(token);
return jwt.getClaim(CLAIM_NAME).asString();
} catch (Exception e) {
return null;
}
}
}

山东掌趣网络科技




推荐阅读