puzhibing
2023-10-08 22199bbdda579861736420fe26c2873ab0f5d21c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.sinata.jwt;
 
import com.alibaba.fastjson.JSON;
import com.sinata.rest.core.util.MD5Util;
import com.sinata.rest.modular.auth.converter.BaseTransferEntity;
import com.sinata.rest.modular.auth.security.impl.Base64SecurityAction;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * jwt测试
 */
public class DecryptTest {
 
    public static void main(String[] args) {
        // 认证信息,随机字符串
        String salt = "w742mp";
        // 认证信息,token
        String token = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJyYW5kb21LZXkiOiJ3NzQybXAiLCJzdWIiOiIxIiwiZXhwIjoxNTkxMjY3NzYzLCJpYXQiOjE1OTA2NjI5NjN9.q2TRbsTf_YnNLaCnmDvM_pNNvHHB3RN69GFzZy5vMcyS2Zl3lyMH1Fsw7sFshtUBn3QQE0m8yqbxa0Qlq_jXAA";
 
        // 模拟请求参数
        Map<String, Object> map = new HashMap<>();
        map.put("id", "11");
        map.put("current", "22");
        map.put("size", "33");
 
        // 1、请求参数实体转Json字符串
        String jsonString = JSON.toJSONString(map);
        // 2、对Json字符串(请求参数)进行Base64加密
        String encode = new Base64SecurityAction().doAction(jsonString);
        // 3、Base64加密后的Json字符串(请求参数) + 随机字符串,进行Md5加密
        String md5 = MD5Util.encrypt(encode + salt);
 
        BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
        // Json字符串(请求参数)进行Base64加密,实体字符串
        baseTransferEntity.setObject(encode);
        // Base64加密后的Json字符串(请求参数) + 随机字符串,进行Md5加密,签名字符串
        baseTransferEntity.setSign(md5);
 
        System.out.println(JSON.toJSONString(baseTransferEntity));
    }
}