token生成(exp+secret+signature)
作者:互联网
head: {"type":"jwt" ,"alg":"RSA"}
payload: {"sid":"sdyx2021*" ,"pwd":"eetrust123!@#"}
signature: RSA(Base64UrlEncode(heard) + "." + Base64UrlEncode(payload) ), secret)
public class JwtUtils {
// 设置token的过期时间是一天
private static final long EXPIRE = 1000 * 60 * 60 * 24;
// 加盐
private static final String APP_SECRET = "eetrust123!@#";
/**
* 获取token
*
* @param id 用户id
* @param nickname 用户昵称
* @return
*/
public static String getJwtToken(String id, String nickname) {
String JwtToken = Jwts.builder()
.setHeaderParam("typ", "JWT")
.setHeaderParam("alg", "HS256")
.setSubject("guli-user")
.setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() + EXPIRE))
.claim("id", id)
.claim("nickname", nickname)
.signWith(SignatureAlgorithm.HS256, APP_SECRET)
.compact();
return JwtToken;
}
………………
}
标签:claim,String,secret,token,static,signature,nickname,id 来源: https://www.cnblogs.com/misted/p/16200125.html