当前位置:网站首页>(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详解 大佬的详解网址,自取
边栏推荐
- Bull: remove common characters
- Rapidly develop GraphScope graph analysis applications
- 2021-05-26
- Test Development Engineer Growth Diary 017 - The Life Cycle of a Bug
- kubernetes搭建SonarQube进行代码扫描
- MongoDB - Introduction, Data Types, Basic Statements
- OP tokens and non-transferable NFTs work to build a new digital democracy
- openstack删除计算节点
- As a test leader, examine several aspects of job candidates
- 快速开发 GraphScope 图分析应用
猜你喜欢
随机推荐
Test the basics 02
Test Development Engineer Growth Diary 017 - The Life Cycle of a Bug
prometheus-federation-tls加密
用于标记蛋白质和抗体的Biotin-LC-Sulfo-NHS|CAS:191671-46-2
Ingress:从静态图分析到动态图分析
OP tokens and non-transferable NFTs work to build a new digital democracy
如何将modelsim仿真数据存成文件
远程连接服务器的MySql
npm安装nodejs环境配置
Mastering JESD204B (2) – Debugging of AD6676
05-Theos
Application of graph computing in network security analysis
使用 Helm 部署 GraphScope
基于 JupyterLab 插件在 GraphScope 中交互式构图
MySql connecting to the server remotely
Multithreading basics (multithreaded memory, security, communication, thread pools and blocking queues)
替换xxx.jar的class文件命令
GAIA-IR:GraphScope 上的并行化图查询引擎
About memcache kernel, so one of the most popular
MYSQL-GROUP BY 用法 全网最精,通熟易懂的话解释









