Java实现基于token认证( 五 )

try {

//超时时间

Date date = new Date(System.currentTimeMillis() + 30 * 1000);

//令牌token

String token = JWT.create().withHeader(header).withClaim(\"userId\" userId).withExpiresAt(date)

.sign(algorithm);

System.out.println(token);

catch (Exception e) {

// TODO: handle exception

2.3 解密

//前端传过来的令牌

String token = \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1Nzg1NTEyOTgsInVzZXJJZCI6ImhlbGxvIn0.mVXwBkBMO-Sr3FJPZSVLezUuxdvMwNsGgRqTCVufH8o\";

//和上面一样的签名

推荐阅读