Skip to content

Commit

Permalink
fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Sep 17, 2021
1 parent 036e732 commit 682b829
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/jwt/概述.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ jwt.getPayload("admin");

### JWT验证

1. 验证签名

```java
String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
"eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9." +
Expand All @@ -113,4 +115,22 @@ byte[] key = "1234567890".getBytes();

// 默认验证HS265的算法
JWT.of(rightToken).setKey(key).verify()
```

2. 详细验证

除了验证签名,Hutool提供了更加详细的验证:`validate`,主要包括:

- Token是否正确
- 生效时间不能晚于当前时间
- 失效时间不能早于当前时间
- 签发时间不能晚于当前时间

使用方式如下:

```java
String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJNb0xpIiwiZXhwIjoxNjI0OTU4MDk0NTI4LCJpYXQiOjE2MjQ5NTgwMzQ1MjAsInVzZXIiOiJ1c2VyIn0.L0uB38p9sZrivbmP0VlDe--j_11YUXTu3TfHhfQhRKc";

byte[] key = "1234567890".getBytes();
boolean validate = JWT.of(token).setKey(key).validate(0);
```

0 comments on commit 682b829

Please sign in to comment.