基于JWT Token 验证

xiaoxiao2021-02-28  104

因项目要前后端彻底分离,故采用JWT 进行验证

JWT 链接地址:https://github.com/auth0/java-jwt

maven  配置:

<dependency> <groupId>com.auth0</groupId> <artifactId>java-jwt</artifactId> <version>3.2.0</version> </dependency>

生成key:

Algorithm algorithmHS = Algorithm.HMAC256("secret");

生成基于RSA的key

//RSA RSAPublicKey publicKey = //Get the key instance RSAPrivateKey privateKey = //Get the key instance Algorithm algorithmRS = Algorithm.RSA256(publicKey, privateKey);

iss(Issuser):代表这个JWT的签发主体; sub(Subject):代表这个JWT的主体,即它的所有人; aud(Audience):代表这个JWT的接收对象; exp(Expiration time):是一个时间戳,代表这个JWT的过期时间; nbf(Not Before):是一个时间戳,代表这个JWT生效的开始时间,意味着在这个时间之前验证JWT是会失败的; iat(Issued at):是一个时间戳,代表这个JWT的签发时间; jti(JWT ID):是JWT的唯一标识。

转载请注明原文地址: https://www.6miu.com/read-47292.html

最新回复(0)