| 8 | import java.util.Map; |
| 9 | |
| 10 | public class JwtUtils { |
| 11 | |
| 12 | private static String signKey = "password"; |
| 13 | private static Long expire = 4320000000L; //表示有效期1200h:1200 * 3600 * 1000 = 43200000 |
| 14 | |
| 15 | /** |
| 16 | * JWT 令牌生成方法 |
| 17 | * @param claims JWT第二部分载荷,paylaod中存储的内容 |
| 18 | * @return |
| 19 | */ |
| 20 | public static String generateJwt(Map<String, Object> claims){ |
| 21 | |
| 22 | String jwttoken = Jwts.builder() |
| 23 | .signWith(SignatureAlgorithm.HS256, signKey) |
| 24 | .setClaims(claims) |
| 25 | .setExpiration(new Date(System.currentTimeMillis() + expire)) |
| 26 | .compact(); |
| 27 | |
| 28 | return jwttoken; |
| 29 | |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * JWT 令牌解析方法 |
| 34 | * @param jwttoken |
| 35 | * @return |
| 36 | */ |
| 37 | public static Claims parseJwt(String jwttoken){ |
| 38 | Claims claims = Jwts.parser() |
| 39 | .setSigningKey(signKey) |
| 40 | .parseClaimsJws(jwttoken) |
| 41 | .getBody(); |
| 42 | |
| 43 | return claims; |
| 44 | } |
| 45 | |
| 46 | } |
nothing calls this directly
no outgoing calls
no test coverage detected