package com.mortals.httpclient;


import io.jsonwebtoken.Header;
import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Base64;


/**
 * @author: zxfei
 * @date: 2022/4/26 15:10
 * @description:
 **/
public class Test {


    public static void main(String[] args) throws Exception {

        String body="eyJpc3MiOiJ5dWxpbnR4IiwiZXhwIjoxNjUxMTEzNDUyLCJhdWQiOiJhcGkiLCJuYmYiOjE2NTA5NDA2NTIsImlhdCI6MTY1MDk0MDY1MiwidXNlckluZm8iOnsiaWQiOjEsInVzZXJfbmFtZSI6Ilx1NGY1OVx1Njc5NyIsImFjY291bnQiOiJhZG1pbiIsInBhc3N3b3JkIjoic2NzbWlsZSIsInVwZGF0ZV90aW1lIjoiMjAyMi0wNC0yMCAxNjozNjo1MyIsInBvc2l0aW9uX2lkIjoxLCJwb3NpdGlvbl9uYW1lIjoiXHU4ZDg1XHU3ZWE3XHU3YmExXHU3NDA2XHU1NDU4IiwiYXV0aCI6WyJzeXNfdXNlclwvbGlzdGRhdGEiLCJzeXNfcG9zaXRpb25cL2xpc3RkYXRhIl19fQ";
        byte[] base64decodedBytes = Base64.getDecoder().decode(body);

        System.out.println("原始字符串: " + new String(base64decodedBytes, "utf-8"));


       // String s = new String(Base64.decode(body), "utf-8");


        String secret="oePmAwAkC6ehBm2aAEbP_Q5yy9fQ";

        String token = Jwts.builder()
                .setHeaderParam("typ","JWT")
                .setPayload("1")
                .signWith(SignatureAlgorithm.HS256, secret)
                .compact();

        System.out.println(token);





        String token1="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.MQ.DA4669tqW3vEwUX2fFnhEE7CqkOMTZBuDXRqYrnVkPc";

        Jwt body1 = Jwts.parser().setSigningKey( Base64.getEncoder().encodeToString(secret.getBytes())).parse(token1);

        System.out.println(body1.getBody());


    }

}
