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());
    }
  • 相关阅读:
    java lambda
    ssh配置基础
    信息安全课程笔记1
    字体标记与文字布局
    字符串:格式化
    字符串
    标签详细描述
    HTML中的标签列表
    html(1)
    python列表命令
  • 原文地址:https://www.cnblogs.com/richard713/p/14437281.html
Copyright © 2011-2022 走看看