Blame view

juvenile-prosecution-boot/jeecg-boot-module-system/src/test/java/org/jeecg/SecurityToolsTest.java 1.72 KB
6c637641   wxy   no message
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
44
45
46
47
48
49
  package org.jeecg;
  
  import cn.hutool.json.JSONObject;
  import org.jeecg.common.util.security.SecurityTools;
  import org.jeecg.common.util.security.entity.*;
  import org.junit.Test;
  
  public class SecurityToolsTest {
      @Test
      public void Test(){
          MyKeyPair mkeyPair = SecurityTools.generateKeyPair();
  
          JSONObject msg = new JSONObject();
          msg.put("name", "党政辉");
          msg.put("age", 50);
          JSONObject identity = new JSONObject();
          identity.put("type", "01");
          identity.put("no", "210882165896524512");
          msg.put("identity", identity);
  
          // 签名加密部分
          SecuritySignReq signReq = new SecuritySignReq();
          // data为要加密的报文字符串
          signReq.setData(msg.toString());
          // 为rsa私钥
          signReq.setPrikey(mkeyPair.getPriKey());
          // 调用签名方法
          SecuritySignResp sign = SecurityTools.sign(signReq);
          // 打印出来加密数据
          // signData为签名数据
          // data为aes加密数据
          // asekey为ras加密过的aeskey
          System.out.println(new JSONObject(sign).toStringPretty());
  
          // 验签解密部分
          SecurityReq req = new SecurityReq();
          //对方传过来的数据一一对应
          req.setAesKey(sign.getAesKey());
          req.setData(sign.getData());
          req.setSignData(sign.getSignData());
          //我们的公钥
          req.setPubKey(mkeyPair.getPubKey());
          //验签方法调用
          SecurityResp securityResp = SecurityTools.valid(req);
          //解密报文data为解密报文
          //sucess 为验签成功失败标志 true代码验签成功,false代表失败
          System.out.println(new JSONObject(securityResp).toStringPretty());
      }
  }