java基础之解密JWT

package com.chinadci.backendservice.common.tokenJWT;

import com.chinadci.backendservice.model.Properties;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;


import javax.xml.bind.DatatypeConverter;

public class ParseJwt
{

  public static Claims parseJWT(String jwt,Properties properties) {

    //This line will throw an exception if it is not a signed JWS (as expected)
    //properties.getJwt_secret()相当于盐值
    Claims claims = Jwts.parser()
      .setSigningKey(DatatypeConverter.parseBase64Binary(properties.getJwt_secret()))
      .parseClaimsJws(jwt).getBody();
    return claims;
  }
}

转自https://stormpath.com/blog/jwt-java-create-verify

你可能感兴趣的:(java基础)