当前位置:网站首页>(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详解 大佬的详解网址,自取
边栏推荐
猜你喜欢

OP 代币和不可转让的 NFT 致力于建立新的数字民主

Vineyard: An open source distributed in-memory data management framework

Mastering JESD204B (3) – Debugging of AD6676

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

测试开发工程师成长日记018 - 测试面试必备题记录(持续更新)

Graph Computing 101: Types, Languages, and Systems of Graph Computing

原力计划微服务实战|集中配置中心Config非对称加密与安全管理

关于memcache内核,全网最通俗的讲解

Test Development Engineer Growth Diary 018 - Record of Required Questions for Test Interview (Continuous Update)

How to save modelsim simulation data as a file
随机推荐
快速开发 GraphScope 图分析应用
从 Vertex 到 Subgraph 再到 PIE: 并行图计算编程模型概览
Test Development Engineer Growth Diary 008 - Talking About Some Bugs/Use Case Management Platform/Collaboration Platform
The Force Plan Microservices | Centralized Configuration Center Config Asymmetric Encryption and Security Management
Test the basics 02
远程连接服务器的MySql
Biotin-PEG4-DADPS-Picolyl-azide(CAS:2599839-59-3)生物素试剂
Biotinyl Cystamine_CAS:128915-82-2_生物素半胱胺
05-Theos
软件测试开发:发送第一封测试报告邮件
OP tokens and non-transferable NFTs work to build a new digital democracy
基于 JupyterLab 插件在 GraphScope 中交互式构图
Test the basics 01
Alamofire source code analysis - POST request
libgrape-lite: 提供 GraphScope 的图分析能力
瀑布流(自定义布局实现)
Biotin-PEG4-SS-Alkyne_1260247-54-8_生物素-PEG4-SS-炔烃
测开基础知识02
Unable to open socket file: target process not responding or HotSpot VM not loaded
Dachang's annual salary of 50w+ recruits test engineers with test platform development capabilities