zoukankan      html  css  js  c++  java
  • JWT使用例子

    引起maven包

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

    try {
    String secret = "chen";// 密钥
    String issUer = "xiaochen";//身份
    Algorithm algorithm = Algorithm.HMAC256(secret);
    String token = JWT.create()
    .withIssuer(issUer)
    .withClaim("loginName", "chenyuepeng").withClaim("userCode", "chenyuepeng")// 要传的参数
    .sign(algorithm);
    System.out.println(token);

    Algorithm algorithm2 = Algorithm.HMAC256(secret);
    JWTVerifier verifier = JWT.require(algorithm2)
    .withIssuer(issUer)
    .build(); //Reusable verifier instance
    DecodedJWT jwt = verifier.verify(token);
    System.out.println("loginName:" + jwt.getClaim("loginName").asString());
    } catch (JWTCreationException exception){
    System.out.println(exception.getMessage());
    }
  • 相关阅读:
    linux常用命令中篇
    htaccess正则规则学习笔记整理
    个性签名
    求函数的单调区间
    函数的奇偶性
    函数的对称性
    函数的周期性
    复合函数
    赋值法
    高中数学中高频变形技巧收录
  • 原文地址:https://www.cnblogs.com/richard713/p/14437281.html
Copyright © 2011-2022 走看看