forked from kidgrow-microservices-platform

克 刘
2020-03-16 549148d90d41a3320bd36d469fd690354c78de58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import com.kidgrow.jwt.utils.JwtHelper;
import com.kidgrow.jwt.utils.JwtUserInfo;
import com.kidgrow.jwt.utils.Token;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @Description: jwt 生成和解析 测试类<br>
 * @Project: <br>
 * @CreateDate: Created in 2020/2/11 14:12 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 */
public class JwtHelperTest {
    /**
     * 验证自己生成的 公钥私钥能否 成功生成token 解析token
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        JwtUserInfo jwtInfo = new JwtUserInfo(1L, "kidgrow", "喜高科技", 1L, 1L);
        int expire = 7200;
 
        //生成Token  注意: 确保该模块 kidgrow-jwt-spring-boot-starter/src/main/resources 目录下已经有了私钥
        Token token = JwtHelper.generateUserToken(jwtInfo, "pri.key", expire);
        System.out.println(token);
 
        //解析Token  注意: 确保该模块 kidgrow-jwt-spring-boot-starter/src/main/resources 目录下已经有了公钥
        JwtUserInfo jwtFromToken = JwtHelper.getJwtFromToken(token.getToken(), "pub.key");
        System.out.println(jwtFromToken);
 
    }
}