Java里JWT的使用方法

简介

header

{
  'typ': 'JWT',
  'alg': 'HS256'
}

playload

{
  "sub": "1234567890",
  "name": "John Doe",
  "admin": true
}

java代码

            String str = Jwts.builder()
                        .setHeaderParam("typ", "JWT")
                        .setHeaderParam("alg", "HS256")
                        .claim("sub","1234567890")
                        .claim("name", "John Doe")
                        .claim("admin", true)
                        .signWith(SignatureAlgorithm.HS256, key.getBytes("UTF-8"))
                        .compact();

你可能感兴趣的:(Java里JWT的使用方法)