package com.jpsoft.shinestar.modules.common.utils;

import java.security.Key;
import java.util.Base64;
import java.util.Date;


import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
/**
 * @author 墨鱼_mo
 * @date 2020-11-2 13:55
 */
public class JwtUtil2 {

    public static String createToken(String jwtSecret, String subject, Date expiration) {
        //token有效时间天
        byte[] privateKey = Base64.getDecoder().decode(jwtSecret);

        Key key = Keys.hmacShaKeyFor(privateKey);

        String token = Jwts.builder()
                .setSubject(subject)
                //设置自定义claims后，setSubject值将失效
//               .setClaims(extraInfo)
                .signWith(key)
                .setExpiration(expiration)
                .compact();

        return "Bearer " + token;
    }
}
