当前位置:网站首页>(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详解 大佬的详解网址,自取
边栏推荐
猜你喜欢
Shortcut keys commonly used in the use of Word
Event Delivery and Responder Chains
DADPS-生物素-炔基_CAS:2241685-22-1试剂反应原理
GNNLab: A Novel GNN System Based on Spatial Sharing Ideas
Application of graph computing in network security analysis
远程连接服务器的MySql
多线程进阶(CountDownLatch,死锁,线程安全集合类)
Mastering JESD204B (2) – Debugging of AD6676
掌握JESD204B(三)–AD6676的调试
Rapidly develop GraphScope graph analysis applications
随机推荐
04-加壳和脱壳
As a test leader, examine several aspects of job candidates
prometheus-basic_auth加密配置
DADPS-生物素-炔基_CAS:2241685-22-1试剂反应原理
Azide-SS-biotin|CAS:1620523-64-9|生物素-二硫键-叠氮可降解 (cleavable) 的 ADC linke
测试开发工程师成长日记003 - 接口自动化框架搭建
npm安装nodejs环境配置
Multithreading basics (concept, create, interrupt)
Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)
Network Protocol 04 - Physical and Data Link Layers
SE_01
GNNLab: A Novel GNN System Based on Spatial Sharing Ideas
GadgetInspector原理分析
GAIA-IR:GraphScope 上的并行化图查询引擎
mysql常用命令以及mysqldump备份
OP 代币和不可转让的 NFT 致力于建立新的数字民主
测试开发工程师成长日记001 - 敏捷测试、CI/CD/CT、DecOps的一些介绍
Dachang's annual salary of 50w+ recruits test engineers with test platform development capabilities
Application of graph computing in network security analysis
The Force Plan Microservices | Centralized Configuration Center Config Asymmetric Encryption and Security Management