当前位置:网站首页>(GGG)JWT
(GGG)JWT
2022-07-30 05:49:00 【Leo丶fei】


以 . 链接
由JWT头部信息header加密得到
由JWT用到的身份验证信息json数据加密得到
由A和B加密得到,是校验部分
导入依赖
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>生成token并且设置失效时间
@Test
void JwtTest() {
//生成token
//1、准备数据
Map map = new HashMap();
map.put("id",123);
map.put("name","rang rang");
//根据当前系统改时间为后面设置失效时间
long now = System.currentTimeMillis();
//2、使用JWT的工具类生成token
String token = Jwts.builder()
.signWith(SignatureAlgorithm.HS512, "rang rang 01") //指定加密算法
.setClaims(map) //写入数据
.setExpiration(new Date(now + 390000)) //失效时间
.compact();
System.out.println(token);
}
解析
@Test
public void parseTest(){
try{String token ="eyJhbGciOiJIUzUxMiJ9.eyJuYW1lIjoicmFuZyByYW5nIiwiaWQiOjEyMywiZXhwIjoxNjU4OTAwODQxfQ.LYLQGfxCwNVbM3Jl_021B1KO78S1785XE9bgd8gknyVMDmGyqsJqsFeSpsf7NhppqPfYy8QxeeEN222pm9v5uw";
Claims body = Jwts.parser().setSigningKey("rang rang 01").parseClaimsJws(token).getBody();
Object id = body.get("id");
Object name = body.get("name");
System.out.println(id);
System.out.println(name);
}catch (ExpiredJwtException e) {
System.out.println("token过期啦");
}catch (SignatureException e) {
System.out.println("token不合法");
}
}

JWT详解 大佬的详解网址,自取
边栏推荐
- Software Testing Terminology - Scenario Testing
- MongoDB-CUD without R
- A New Paradigm for Distributed Deep Learning Programming: Global Tensor
- Bull: remove common characters
- Selenium01
- 陕西Biotin-LC_CAS:72040-64-3_N-生物素氨基己酸供应商价格
- DADPS-生物素-炔基_CAS:2241685-22-1试剂反应原理
- 软件测试_01
- Waterfall flow (custom layout implementation)
- Data types of Redis6
猜你喜欢

Biotin-SS-NHS ester|生物素-二硫键-活性酯|CAS:122266-55-1具有良好的水溶性

As a test leader, examine several aspects of job candidates

藏不住了,我要揭露云原生的那些不好

Mastering JESD204B (2) – Debugging of AD6676

测试开发工程师成长日记017 - bug的生命周期

Biotin-PEG4-SS-Alkyne_1260247-54-8_生物素-PEG4-SS-炔烃

PC DBCO-PEG3-Biotin|PC-生物素-PEG3-DBCO可用于使用无铜点击化学

为数字政府构建智能化网络安全管控体系

Test Development Engineer Growth Diary 001 - Some Introduction to Agile Testing, CI/CD/CT, DecOps

About memcache kernel, so one of the most popular
随机推荐
Test the basics 01
Graph analysis like NetworkX with GraphScope
测试开发工程师成长日记010 - Jenkins中的CI/CD/CT(持续集成构建/持续交付/持续测试)
02-Cycript的使用
网络协议01 - 基础概念
02-Use of Cycript
使用 Grafana 的 Redis Data Source 插件监控 Redis
Alamofire源码分析 - POST请求
藏不住了,我要揭露云原生的那些不好
Test Development Engineer Growth Diary 018 - Record of Required Questions for Test Interview (Continuous Update)
openstack删除计算节点
测试开发工程师成长日记015 - 最强20道测试面试题
Selenium01
libgrape-lite on GPUs: GPU helps accelerate graph analysis tasks
陕西Biotin-LC_CAS:72040-64-3_N-生物素氨基己酸供应商价格
mysql常用命令以及mysqldump备份
From installation to compilation: 10 minutes to teach you to use and develop GraphScope locally
图计算在网络安全分析中的应用
04-加壳和脱壳
Ingress:从静态图分析到动态图分析