Java实现基于token认证( 七 )

try {

Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);

Map<String Object> header = new HashMap<String Object>();

header.put(\"typ\" \"JWT\");

header.put(\"alg\" \"HS256\");

Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);

String token = JWT.create().withHeader(header).withClaim(CLAIM_NAME sign).withExpiresAt(date)

.sign(algorithm);

return token;

catch (Exception e) {

return null;

public static String verify(String token) {

推荐阅读