add 调用制修订接口 ZxdUtil.java

This commit is contained in:
lijiarao
2024-06-06 09:15:26 +08:00
parent ac86f82147
commit 42b5064a54
3 changed files with 84 additions and 29 deletions
+5
View File
@@ -78,5 +78,10 @@
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
<version>1.69</version>
</dependency>
</dependencies>
</project>
@@ -12,6 +12,7 @@ import com.jero.contract.entity.ThereContract;
import com.jero.project.entity.PayResearchProject;
import com.jero.project.mapper.PayResearchProjectMapper;
import com.jero.project.service.IPayResearchProjectService;
import com.jero.util.ZxdUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.Charsets;
@@ -72,39 +73,12 @@ public class PayResearchProjectServiceImpl extends ServiceImpl<PayResearchProjec
private PayResearchProjectMapper payResearchProjectMapper;
@Resource
private RedisUtil redisUtil;
/**
* 加密,并将结果转成16进制字符串
*
*/
public static String encrypt(String datasource, String password) {
try {
SecureRandom random = new SecureRandom();
DESKeySpec desKey = new DESKeySpec(password.getBytes(Charsets.UTF_8));
// 创建一个密匙工厂,然后用它把DESKeySpec转换成
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(desKey);
// Cipher对象实际完成加密操作
Cipher cipher = Cipher.getInstance("DES");
// 用密匙初始化Cipher对象
cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
// 现在,获取数据并加密
// 正式执行加密操作
byte[] result = cipher.doFinal(datasource.getBytes(Charsets.UTF_8));
// 转成16进制
return Hex.encodeHexString(result);
} catch (Throwable e) {
e.printStackTrace();
log.error(String.valueOf(e));
}
return null;
}
@Override
public JSONObject listForThree(Integer pageNo, Integer pageSize, String abbreviation,String projectName) {
String s = PREFIXS + abbreviation;
String encrypt = encrypt(s, KEYS);
String encrypt = ZxdUtil.encrypt(s, KEYS);
HashMap<String, Object> map = new HashMap<>();
map.put("appId","QC_APP01");
map.put("abbreviation",encrypt);
@@ -137,7 +111,7 @@ public class PayResearchProjectServiceImpl extends ServiceImpl<PayResearchProjec
response.setHeader("Content-Disposition", "attachment;filename=" + hehe);
OutputStream outputStream = response.getOutputStream();
String s = PREFIXF + fileId;
String encrypt = encrypt(s, KEYS);
String encrypt = ZxdUtil.encrypt(s, KEYS);
HashMap<String, Object> map = new HashMap<>();
map.put("appId", "QC_APP01");
map.put("fid", encrypt);
@@ -0,0 +1,76 @@
package com.jero.util;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SM4;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.Charsets;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.SecureRandom;
import java.util.HashMap;
/**
* 对接制修订接口
* @author liJiaRao
* @date 2024-06-05 10:36
*/
@Slf4j
public class ZxdUtil {
/**
* 加密,并将结果转成16进制字符串
*
*/
public static String encrypt(String datasource, String password) {
try {
SecureRandom random = new SecureRandom();
DESKeySpec desKey = new DESKeySpec(password.getBytes(Charsets.UTF_8));
// 创建一个密匙工厂,然后用它把DESKeySpec转换成
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(desKey);
// Cipher对象实际完成加密操作
Cipher cipher = Cipher.getInstance("DES");
// 用密匙初始化Cipher对象
cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
// 现在,获取数据并加密
// 正式执行加密操作
byte[] result = cipher.doFinal(datasource.getBytes(Charsets.UTF_8));
// 转成16进制
return Hex.encodeHexString(result);
} catch (Throwable e) {
e.printStackTrace();
log.error(String.valueOf(e));
}
return null;
}
private final static String SM4_KEY="QC_APP01!!$QIche";//密匙
private final static String KEYS="qczxd00001_memberSystem";//密匙
private final static String APP_ID="QC_APP01";//appId
private final static String PREFIXS ="appId=QC_APP01&type=getCommiteeAndMemberInfo";//列表获取参数
private final static String URL ="http://www.catarc.org.cn:8088/zxd/serviceInterface/getCommiteeAndMemberInfo";//列表地址
public static void getWyh(){
String encrypt = ZxdUtil.encrypt(PREFIXS, KEYS);
HashMap<String, Object> map = new HashMap<>();
map.put("appId",APP_ID);
map.put("abbreviation",encrypt);
String s1 = HttpUtil.get(URL, map);
SM4 sm4 = SmUtil.sm4(SM4_KEY.getBytes());
String str = sm4.decryptStr(s1);
JSONObject jsonObject = JSONObject.parseObject(str);
log.info(jsonObject.toJSONString());
}
public static void main(String[] args) {
getWyh();
}
}