package com.yuanchu.limslaboratory.utils;
|
|
|
import com.auth0.jwt.JWT;
|
import com.auth0.jwt.algorithms.Algorithm;
|
import com.auth0.jwt.exceptions.JWTCreationException;
|
|
import java.util.Date;
|
|
public class JwtUtils {
|
// 过期时间 2 小时
|
// private static final long EXPIRE_TIME = 2 * 60 * 60 * 1000;
|
|
private static final long EXPIRE_TIME = 10;
|
/**
|
* 生成签名,准确地说是生成token
|
* @param secret
|
* @return
|
*/
|
public static String sign(String account, String secret){
|
try{
|
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
|
Algorithm algorithm = Algorithm.HMAC256(secret);
|
//附带username,nickname信息
|
return JWT.create()
|
.withClaim("account",account)
|
.withExpiresAt(date)
|
.sign(algorithm);
|
} catch (JWTCreationException e){
|
e.printStackTrace();
|
return null;
|
} catch (Exception e){
|
e.printStackTrace();
|
return null;
|
}
|
}
|
}
|