mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-31 01:01:27 +08:00
Jeecg-Boot 2.1.0 版本发布,Online表单开发&在线代码生成器(迟到的版本)
This commit is contained in:
@ -0,0 +1,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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user