当前位置:网站首页>(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详解 大佬的详解网址,自取
边栏推荐
- 快速开发 GraphScope 图分析应用
- 02-Use of Cycript
- 如何将modelsim仿真数据存成文件
- 为数字政府构建智能化网络安全管控体系
- 图计算101:图计算的类型、语言与系统
- Interactively compose graphs in GraphScope based on the JupyterLab plugin
- OP tokens and non-transferable NFTs work to build a new digital democracy
- MongoDB - Introduction, Data Types, Basic Statements
- 用 GraphScope 像 NetworkX 一样做图分析
- Vineyard: 开源分布式内存数据管理框架
猜你喜欢
Mastering JESD204B (1) – Debugging of AD6676
如何将modelsim仿真数据存成文件
How to create a shortcut without the "shortcut" suffix?
Multithreading basics (multithreaded memory, security, communication, thread pools and blocking queues)
prometheus监控nacos
多线程进阶(锁策略,自旋+CAS,Synchronized,JUC,信号量)
MongoDB-CUD没有R
flask项目快速搭建部署gunicorn+supervisor
测试开发工程师成长日记016 - 关于提测的那些事
从 Vertex 到 Subgraph 再到 PIE: 并行图计算编程模型概览
随机推荐
Proftpd配置文件
关于memcache内核,全网最通俗的讲解
2021-05-26
wsl2设置静态ip(固定ip)static ip
GAIA-IR: Parallelized Graph Query Engine on GraphScope
含 3 个单元 PEG 的 ADC linker的PC DBCO-PEG3-Biotin
Advanced multi-threading (CountDownLatch, deadlock, thread-safe collection class)
测试开发工程师成长日记010 - Jenkins中的CI/CD/CT(持续集成构建/持续交付/持续测试)
Alamofire源码分析 - POST请求
Event Delivery and Responder Chains
MySQL common commands and mysqldump backup
Unable to open socket file: target process not responding or HotSpot VM not loaded
多线程基础(多线程内存,安全,通信,线程池和阻塞队列)
About memcache kernel, so one of the most popular
Graph Computing 101: Types, Languages, and Systems of Graph Computing
掌握JESD204B(一)–AD6676的调试
Mastering JESD204B (3) – Debugging of AD6676
MongoDB - query
使用 Grafana 的 Redis Data Source 插件监控 Redis
GadgetInspector原理分析