All Downloads are FREE. Search and download functionalities are using the official Maven repository.

matrix.business.oauth2.utils.JwtUtil Maven / Gradle / Ivy

package matrix.business.oauth2.utils;

import matrix.business.oauth2.dto.VerifierKeyDto;
import org.springframework.security.jwt.Jwt;
import org.springframework.security.jwt.JwtHelper;
import org.springframework.security.jwt.crypto.sign.MacSigner;
import org.springframework.security.jwt.crypto.sign.RsaVerifier;

/**
 * jwt工具
 * @author wangcheng
 * 2021/9/3
 **/
public class JwtUtil {

    /**
     * 验证并获取jwt token
     * @param verifierKey 验证参数
     * @param token token字符串
     * @return token信息
     */
    public static Jwt verify(VerifierKeyDto verifierKey, String token) {
        if (verifierKey.getAlg().endsWith("RSA")) {
            return JwtHelper.decodeAndVerify(token, new RsaVerifier(verifierKey.getValue().replace("\\n", "")));
        }
        return JwtHelper.decodeAndVerify(token, new MacSigner(verifierKey.getValue()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy