2.不分参数名和类名冲突调整 3.新增人脸识别失败的错误信息枚举,并返回错误信息. 4.体检影像报告查询交互加密调整 5.电子健康卡人脸识别接口,区别于微信人脸识别接口,签名生成调整.debug
parent
2a53cbf4fd
commit
ec5fdd390f
36 changed files with 708 additions and 369 deletions
@ -0,0 +1,36 @@ |
||||
package com.ynxbd.common.bean.enums; |
||||
|
||||
import lombok.ToString; |
||||
|
||||
@ToString |
||||
public enum WxFaceEnum { |
||||
E40003(40003, "[认证失败]openid无效"), |
||||
E84010(84010, "缺少out_seq_no 参数"), |
||||
E84011(84011, "out_seq_no 格式无效"), |
||||
E84012(84012, "缺少cert_info参数"), |
||||
E84013(84013, "证件类型无效"), |
||||
E84014(84014, "证件姓名无效"), |
||||
E84015(84015, "证件号码无效"), |
||||
E84016(84016, "缺少openid参数"), |
||||
E84019(84019, "out_seq_no 已存在,请更换新的 out_seq_no"); |
||||
|
||||
public final Integer code; |
||||
public final String msg; |
||||
|
||||
WxFaceEnum(Integer code, String msg) { |
||||
this.code = code; |
||||
this.msg = msg; |
||||
} |
||||
|
||||
public static WxFaceEnum findEnum(Integer code) { |
||||
if (code == null) { |
||||
return null; |
||||
} |
||||
for (WxFaceEnum value : values()) { |
||||
if (value.code.equals(code)) { |
||||
return value; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
@ -0,0 +1,20 @@ |
||||
package com.ynxbd.common.bean.xk; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.Setter; |
||||
import lombok.ToString; |
||||
|
||||
// 给要途径字典
|
||||
@Setter |
||||
@Getter |
||||
@ToString |
||||
@NoArgsConstructor |
||||
public class HisRxAdmRoute { |
||||
// Code 编码
|
||||
private String code; |
||||
// Name 名称
|
||||
private String name; |
||||
// PYM 拼音码
|
||||
private String pym; |
||||
} |
||||
@ -0,0 +1,50 @@ |
||||
package com.ynxbd.common.bean.xk; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.Setter; |
||||
import lombok.ToString; |
||||
|
||||
// 药品
|
||||
@Setter |
||||
@Getter |
||||
@ToString |
||||
@NoArgsConstructor |
||||
public class HisRxDrug { |
||||
// Code 商品代码
|
||||
private String code; |
||||
// Name 商品名称
|
||||
private String name; |
||||
// ProductPlace 产地
|
||||
private String productPlace; |
||||
// UnitName 单位名称
|
||||
private String unitName; |
||||
// UnitName 最小单位名称
|
||||
private String minUnitName; |
||||
// Persent 批零比
|
||||
private Double persent; |
||||
// YPJL 药品剂量
|
||||
private Double ypjl; |
||||
// YPJL_Unit 药品剂量单位
|
||||
private String ypjlUnit; |
||||
// Price 零售单价
|
||||
private Double price; |
||||
// Count 库存数量
|
||||
private Integer count; |
||||
// YFCode 药房代码
|
||||
private String yfCode; |
||||
// YFName 药房名称
|
||||
private String yfName; |
||||
// GOODSID 批次号
|
||||
private String goodsId; |
||||
// Indate 效期
|
||||
private String indate; |
||||
// KMCode 财务科目代码
|
||||
private String kmCode; |
||||
// KMName 财务科目名称
|
||||
private String kmName; |
||||
// YBLB 医保类别
|
||||
private String yblb; |
||||
// YBLBName 医保类别名称
|
||||
private String yblbName; |
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
package com.ynxbd.common.bean.xk; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.Setter; |
||||
import lombok.ToString; |
||||
|
||||
// 药房字典
|
||||
@Setter |
||||
@Getter |
||||
@ToString |
||||
@NoArgsConstructor |
||||
public class HisRxPharmDict { |
||||
// Code 编码
|
||||
private String code; |
||||
// Name 名称
|
||||
private String name; |
||||
} |
||||
@ -0,0 +1,23 @@ |
||||
package com.ynxbd.common.bean.xk; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.NoArgsConstructor; |
||||
import lombok.Setter; |
||||
import lombok.ToString; |
||||
|
||||
@Setter |
||||
@Getter |
||||
@ToString |
||||
@NoArgsConstructor |
||||
public class HisRxUseCount { |
||||
// Code 编码
|
||||
private String code; |
||||
// Name 名称
|
||||
private String name; |
||||
// CountForDay 一天使用次数
|
||||
private Integer countForDay; |
||||
// CountForWeek 一周使用次数
|
||||
private Integer countForWeek; |
||||
// PYM 拼音码
|
||||
private String pym; |
||||
} |
||||
@ -0,0 +1,38 @@ |
||||
package com.ynxbd.common.dao.his; |
||||
|
||||
import com.ynxbd.common.bean.xk.HisRxAdmRoute; |
||||
import com.ynxbd.common.bean.xk.HisRxDrug; |
||||
import com.ynxbd.common.bean.xk.HisRxPharmDict; |
||||
import com.ynxbd.common.bean.xk.HisRxUseCount; |
||||
import com.ynxbd.common.helper.his.HisEnum; |
||||
import com.ynxbd.common.helper.his.HisHelper; |
||||
import com.ynxbd.common.result.JsonResult; |
||||
import com.ynxbd.common.result.ServiceException; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
public class HisXKDao { |
||||
|
||||
public List<?> queryHisRxDict(String type) { |
||||
JsonResult jsonResult = HisHelper.getJsonResult(HisEnum.HIS_XK_RX_DICT, params -> { |
||||
params.put("Flag", type); // 1:用药频次字典; 2:给要途径字典; 3:药房字典; 4:药品
|
||||
}); |
||||
if ("1".equals(type)) { // 用药频次字典
|
||||
return jsonResult.getDataMapList(HisRxUseCount.class, "Items", "Item"); |
||||
} |
||||
if ("2".equals(type)) { // 给要途径字典
|
||||
return jsonResult.getDataMapList(HisRxAdmRoute.class, "Items", "Item"); |
||||
} |
||||
if ("3".equals(type)) { // 药房字典
|
||||
return jsonResult.getDataMapList(HisRxPharmDict.class, "Items", "Item"); |
||||
} |
||||
if ("4".equals(type)) { // 药品
|
||||
return jsonResult.getDataMapList(HisRxDrug.class, "Items", "Item"); |
||||
} |
||||
return new ArrayList<>(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
package com.ynxbd.common.helper.rsa; |
||||
|
||||
import lombok.ToString; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
@ToString |
||||
public class RSAEnum { |
||||
} |
||||
@ -1,248 +1,251 @@ |
||||
package com.ynxbd.common.helper.common; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.codec.binary.Base64; |
||||
import org.apache.commons.lang3.ObjectUtils; |
||||
|
||||
import javax.crypto.Cipher; |
||||
import java.net.URLEncoder; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.security.*; |
||||
import java.security.interfaces.RSAPrivateKey; |
||||
import java.security.interfaces.RSAPublicKey; |
||||
import java.security.spec.PKCS8EncodedKeySpec; |
||||
import java.security.spec.X509EncodedKeySpec; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* RSA非对称加密 |
||||
* |
||||
* @Author wsq |
||||
* @Date 2021/07/28 11:01:28 |
||||
* @Copyright @ 2020 云南新八达科技有限公司 All rights reserved. |
||||
*/ |
||||
@Slf4j |
||||
public class RSAHelper { |
||||
private RSAHelper() { |
||||
} |
||||
|
||||
private static final int KEY_LENGTH = 1024; |
||||
private static final Map<Integer, String> KEY_MAP = new HashMap<>(); // 用于封装随机产生的公钥与私钥
|
||||
|
||||
|
||||
static { |
||||
try { |
||||
// KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象
|
||||
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA"); |
||||
// 初始化密钥对生成器,密钥大小为96-1024位
|
||||
keyPairGen.initialize(KEY_LENGTH, new SecureRandom()); |
||||
// 生成一个密钥对,保存在keyPair中
|
||||
KeyPair keyPair = keyPairGen.generateKeyPair(); |
||||
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); // 得到私钥
|
||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); // 得到公钥
|
||||
String publicKeyStr = new String(Base64.encodeBase64(publicKey.getEncoded())); |
||||
// 得到私钥字符串
|
||||
String privateKeyStr = new String(Base64.encodeBase64((privateKey.getEncoded()))); |
||||
// 将公钥和私钥保存到Map
|
||||
KEY_MAP.put(0, publicKeyStr); // 0表示公钥
|
||||
KEY_MAP.put(1, privateKeyStr); // 1表示私钥
|
||||
} catch (Exception e) { |
||||
ErrorHelper.println(e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取公钥 |
||||
* |
||||
* @return 公钥 |
||||
*/ |
||||
public static String getPublicKey() { |
||||
return KEY_MAP.get(0); |
||||
} |
||||
|
||||
/** |
||||
* 获取私钥 |
||||
* |
||||
* @return 私钥 |
||||
*/ |
||||
public static String getPrivateKey() { |
||||
return KEY_MAP.get(1); |
||||
} |
||||
|
||||
/** |
||||
* RSA公钥加密 |
||||
* |
||||
* @param encryptData 加密数据 |
||||
* @return 密文 |
||||
*/ |
||||
public static String encrypt(String encryptData) { |
||||
return encrypt(encryptData, getPublicKey()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* RSA公钥加密 |
||||
* |
||||
* @param encryptData 加密数据 |
||||
* @return 密文 |
||||
*/ |
||||
public static String encrypt(String encryptData, String publicKey) { |
||||
if (ObjectUtils.isEmpty(encryptData)) { |
||||
return null; |
||||
} |
||||
try { |
||||
// Base64编码的公钥
|
||||
byte[] decoded = Base64.decodeBase64(publicKey); |
||||
RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); |
||||
// RSA加密
|
||||
Cipher cipher = Cipher.getInstance("RSA"); |
||||
cipher.init(Cipher.ENCRYPT_MODE, pubKey); |
||||
return Base64.encodeBase64String(cipher.doFinal(encryptData.getBytes(StandardCharsets.UTF_8))); |
||||
} catch (Exception e) { |
||||
log.error("[RSA]加密失败:[{}]", e.getMessage()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* RSA私钥解密 |
||||
* |
||||
* @param decryptData 加密数据 |
||||
* @return 明文 |
||||
*/ |
||||
public static String decrypt(String decryptData) { |
||||
return decrypt(decryptData, getPrivateKey()); |
||||
} |
||||
|
||||
/** |
||||
* RSA私钥解密 |
||||
* |
||||
* @param decryptData 加密数据 |
||||
* @return 明文 |
||||
*/ |
||||
public static String decrypt(String decryptData, String privateKey) { |
||||
if (ObjectUtils.isEmpty(decryptData)) { |
||||
return null; |
||||
} |
||||
try { |
||||
// 64位解码加密后的字符串
|
||||
byte[] inputByte = Base64.decodeBase64(decryptData.getBytes(StandardCharsets.UTF_8)); |
||||
// base64编码的私钥
|
||||
byte[] decoded = Base64.decodeBase64(privateKey); |
||||
RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded)); |
||||
// RSA解密
|
||||
Cipher cipher = Cipher.getInstance("RSA"); |
||||
cipher.init(Cipher.DECRYPT_MODE, priKey); |
||||
return new String(cipher.doFinal(inputByte)); |
||||
} catch (Exception e) { |
||||
log.error("[RSA]解密失败:[{}]", e.getMessage()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
public static String URLEncode(String data) { |
||||
try { |
||||
if (ObjectUtils.isEmpty(data)) return null; |
||||
return URLEncoder.encode(data, String.valueOf(StandardCharsets.UTF_8)); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static PublicKey getPublicKey(String base64PubKey) { |
||||
try { |
||||
byte[] keyBytes = java.util.Base64.getDecoder().decode(base64PubKey); |
||||
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes); |
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
||||
return keyFactory.generatePublic(spec); |
||||
} catch (Exception e) { |
||||
log.error("", e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* PKCS8 格式私钥字符串转 PrivateKey |
||||
* |
||||
* @param privateKeyStr 带/不带头尾标记的base64私钥 |
||||
* @return PrivateKey |
||||
*/ |
||||
public static PrivateKey getPrivateKey(String privateKeyStr) { |
||||
try { |
||||
// 去除头尾标记、换行、空格
|
||||
String privateKeyPEM = privateKeyStr |
||||
.replace("-----BEGIN PRIVATE KEY-----", "") |
||||
.replace("-----END PRIVATE KEY-----", "") |
||||
.replaceAll("\\s+", ""); |
||||
byte[] keyBytes = java.util.Base64.getDecoder().decode(privateKeyPEM); |
||||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); |
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
||||
return keyFactory.generatePrivate(spec); |
||||
} catch (Exception e) { |
||||
log.error("", e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
// 加密方法(PKCS#1 v1.5填充)
|
||||
public static byte[] enBytePKCS1Padding(String content, String base64PublicKey) throws Exception { |
||||
PublicKey publicKey = getPublicKey(base64PublicKey); |
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); |
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey); |
||||
byte[] rawData = content.getBytes(StandardCharsets.UTF_8); |
||||
return cipher.doFinal(rawData); |
||||
} |
||||
|
||||
// 加密方法(PKCS#1 v1.5填充)
|
||||
public static String enPKCS1Padding(String plaintext, PublicKey publicKey) throws Exception { |
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); |
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey); |
||||
byte[] encryptedBytes = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8)); |
||||
return java.util.Base64.getEncoder().encodeToString(encryptedBytes); |
||||
} |
||||
|
||||
// 解密方法
|
||||
public static String dePKCS1Padding(String encryptedText, PrivateKey privateKey) throws Exception { |
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); |
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey); |
||||
byte[] decryptedBytes = cipher.doFinal(java.util.Base64.getDecoder().decode(encryptedText)); |
||||
return new String(decryptedBytes, StandardCharsets.UTF_8); |
||||
} |
||||
|
||||
// 去除空格、制表符、换行符等连续或多个空白符
|
||||
public static String replaceKey(String key) { |
||||
if (key == null) return null; |
||||
return key.replaceAll("\\s+", ""); |
||||
} |
||||
|
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
// System.out.println("随机生成的公钥为:" + KEY_MAP.get(0));
|
||||
// System.out.println("随机生成的私钥为:" + KEY_MAP.get(1));
|
||||
} |
||||
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// // Base64编码的公钥
|
||||
// byte[] decoded = Base64.decodeBase64(getPublicKey());
|
||||
// RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
|
||||
// // RSA加密
|
||||
// Cipher cipher = Cipher.getInstance("RSA");
|
||||
// cipher.init(Cipher.ENCRYPT_MODE, pubKey);
|
||||
//
|
||||
// String a = Base64.encodeBase64String(cipher.doFinal("encryptData".getBytes(StandardCharsets.UTF_8)));
|
||||
// System.out.println(a);
|
||||
//
|
||||
// String b = Base64.encodeBase64String(cipher.doFinal("encryptData".getBytes(StandardCharsets.UTF_8)));
|
||||
// System.out.println(a);
|
||||
//
|
||||
// String c = Base64.encodeBase64String(cipher.doFinal("encryptData".getBytes(StandardCharsets.UTF_8)));
|
||||
// System.out.println(a);
|
||||
//
|
||||
// String d = Base64.encodeBase64String(cipher.doFinal("encryptData".getBytes(StandardCharsets.UTF_8)));
|
||||
// System.out.println(a);
|
||||
// }
|
||||
} |
||||
package com.ynxbd.common.helper.rsa; |
||||
|
||||
import com.ynxbd.common.helper.common.ErrorHelper; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.codec.binary.Base64; |
||||
import org.apache.commons.lang3.ObjectUtils; |
||||
|
||||
import javax.crypto.Cipher; |
||||
import java.net.URLEncoder; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.security.*; |
||||
import java.security.interfaces.RSAPrivateKey; |
||||
import java.security.interfaces.RSAPublicKey; |
||||
import java.security.spec.PKCS8EncodedKeySpec; |
||||
import java.security.spec.X509EncodedKeySpec; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* RSA非对称加密 |
||||
* |
||||
* @Author wsq |
||||
* @Date 2021/07/28 11:01:28 |
||||
* @Copyright @ 2020 云南新八达科技有限公司 All rights reserved. |
||||
*/ |
||||
@Slf4j |
||||
public class RSAHelper { |
||||
private RSAHelper() { |
||||
} |
||||
|
||||
private static final int KEY_LENGTH = 1024; |
||||
private static final Map<Integer, String> KEY_MAP = new HashMap<>(); // 用于封装随机产生的公钥与私钥
|
||||
|
||||
static { |
||||
try { |
||||
// KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象
|
||||
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA"); |
||||
// 初始化密钥对生成器,密钥大小为96-1024位
|
||||
keyPairGen.initialize(KEY_LENGTH, new SecureRandom()); |
||||
// 生成一个密钥对,保存在keyPair中
|
||||
KeyPair keyPair = keyPairGen.generateKeyPair(); |
||||
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); // 得到私钥
|
||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); // 得到公钥
|
||||
String publicKeyStr = new String(Base64.encodeBase64(publicKey.getEncoded())); |
||||
// 得到私钥字符串
|
||||
String privateKeyStr = new String(Base64.encodeBase64((privateKey.getEncoded()))); |
||||
// 将公钥和私钥保存到Map
|
||||
KEY_MAP.put(0, publicKeyStr); // 0表示公钥
|
||||
KEY_MAP.put(1, privateKeyStr); // 1表示私钥
|
||||
} catch (Exception e) { |
||||
ErrorHelper.println(e); |
||||
} |
||||
} |
||||
|
||||
public static final String RSA_ECB_PKCS1Padding = "RSA/ECB/PKCS1Padding"; |
||||
|
||||
/** |
||||
* 获取公钥 |
||||
* |
||||
* @return 公钥 |
||||
*/ |
||||
public static String getPublicKey() { |
||||
return KEY_MAP.get(0); |
||||
} |
||||
|
||||
/** |
||||
* 获取私钥 |
||||
* |
||||
* @return 私钥 |
||||
*/ |
||||
public static String getPrivateKey() { |
||||
return KEY_MAP.get(1); |
||||
} |
||||
|
||||
/** |
||||
* RSA公钥加密 |
||||
* |
||||
* @param encryptData 加密数据 |
||||
* @return 密文 |
||||
*/ |
||||
public static String encrypt(String encryptData) { |
||||
return encrypt(encryptData, getPublicKey()); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* RSA公钥加密 |
||||
* |
||||
* @param encryptData 加密数据 |
||||
* @return 密文 |
||||
*/ |
||||
public static String encrypt(String encryptData, String publicKey) { |
||||
if (ObjectUtils.isEmpty(encryptData)) { |
||||
return null; |
||||
} |
||||
try { |
||||
// Base64编码的公钥
|
||||
byte[] decoded = Base64.decodeBase64(publicKey); |
||||
RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded)); |
||||
// RSA加密
|
||||
Cipher cipher = Cipher.getInstance("RSA"); |
||||
cipher.init(Cipher.ENCRYPT_MODE, pubKey); |
||||
return Base64.encodeBase64String(cipher.doFinal(encryptData.getBytes(StandardCharsets.UTF_8))); |
||||
} catch (Exception e) { |
||||
log.error("[RSA]加密失败:[{}]", e.getMessage()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* RSA私钥解密 |
||||
* |
||||
* @param decryptData 加密数据 |
||||
* @return 明文 |
||||
*/ |
||||
public static String decrypt(String decryptData) { |
||||
return decrypt(decryptData, getPrivateKey()); |
||||
} |
||||
|
||||
/** |
||||
* RSA私钥解密 |
||||
* |
||||
* @param decryptData 加密数据 |
||||
* @return 明文 |
||||
*/ |
||||
public static String decrypt(String decryptData, String privateKey) { |
||||
if (ObjectUtils.isEmpty(decryptData)) { |
||||
return null; |
||||
} |
||||
try { |
||||
// 64位解码加密后的字符串
|
||||
byte[] inputByte = Base64.decodeBase64(decryptData.getBytes(StandardCharsets.UTF_8)); |
||||
// base64编码的私钥
|
||||
byte[] decoded = Base64.decodeBase64(privateKey); |
||||
RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded)); |
||||
// RSA解密
|
||||
Cipher cipher = Cipher.getInstance("RSA"); |
||||
cipher.init(Cipher.DECRYPT_MODE, priKey); |
||||
return new String(cipher.doFinal(inputByte)); |
||||
} catch (Exception e) { |
||||
log.error("[RSA]解密失败:[{}]", e.getMessage()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
public static String URLEncode(String data) { |
||||
try { |
||||
if (ObjectUtils.isEmpty(data)) return null; |
||||
return URLEncoder.encode(data, String.valueOf(StandardCharsets.UTF_8)); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static PublicKey getPublicKey(String base64PubKey) { |
||||
try { |
||||
byte[] keyBytes = java.util.Base64.getDecoder().decode(base64PubKey); |
||||
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes); |
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
||||
return keyFactory.generatePublic(spec); |
||||
} catch (Exception e) { |
||||
log.error("", e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* PKCS8 格式私钥字符串转 PrivateKey |
||||
* |
||||
* @param privateKeyStr 带/不带头尾标记的base64私钥 |
||||
* @return PrivateKey |
||||
*/ |
||||
public static PrivateKey getPrivateKey(String privateKeyStr) { |
||||
try { |
||||
// 去除头尾标记、换行、空格
|
||||
String privateKeyPEM = privateKeyStr |
||||
.replace("-----BEGIN PRIVATE KEY-----", "") |
||||
.replace("-----END PRIVATE KEY-----", "") |
||||
.replaceAll("\\s+", ""); |
||||
byte[] keyBytes = java.util.Base64.getDecoder().decode(privateKeyPEM); |
||||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); |
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
||||
return keyFactory.generatePrivate(spec); |
||||
} catch (Exception e) { |
||||
log.error("", e); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
// 加密方法(PKCS#1 v1.5填充)[对应前端JS加密]
|
||||
public static byte[] enPKCS1PaddingToByte(String content, String base64PublicKey) throws Exception { |
||||
return enPKCS1PaddingToByte(content, getPublicKey(base64PublicKey)); |
||||
} |
||||
|
||||
public static byte[] enPKCS1PaddingToByte(String content, PublicKey publicKey) throws Exception { |
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); |
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey); |
||||
byte[] data = content.getBytes(StandardCharsets.UTF_8); |
||||
return cipher.doFinal(data); |
||||
} |
||||
|
||||
// 加密方法(PKCS#1 v1.5填充)[对应前端JS加密]
|
||||
public static String enPKCS1Padding(String content, PublicKey publicKey) throws Exception { |
||||
byte[] data = enPKCS1PaddingToByte(content, publicKey); |
||||
return java.util.Base64.getEncoder().encodeToString(data); |
||||
} |
||||
|
||||
// 解密方法
|
||||
public static String dePKCS1Padding(String encryptedText, PrivateKey privateKey) throws Exception { |
||||
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); |
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey); |
||||
byte[] decryptedBytes = cipher.doFinal(java.util.Base64.getDecoder().decode(encryptedText)); |
||||
return new String(decryptedBytes, StandardCharsets.UTF_8); |
||||
} |
||||
|
||||
// 去除空格、制表符、换行符等连续或多个空白符
|
||||
public static String replaceKey(String key) { |
||||
if (key == null) return null; |
||||
return key.replaceAll("\\s+", ""); |
||||
} |
||||
|
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
// System.out.println("随机生成的公钥为:" + KEY_MAP.get(0));
|
||||
// System.out.println("随机生成的私钥为:" + KEY_MAP.get(1));
|
||||
} |
||||
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// // Base64编码的公钥
|
||||
// byte[] decoded = Base64.decodeBase64(getPublicKey());
|
||||
// RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));
|
||||
// // RSA加密
|
||||
// Cipher cipher = Cipher.getInstance("RSA");
|
||||
// cipher.init(Cipher.ENCRYPT_MODE, pubKey);
|
||||
//
|
||||
// String a = Base64.encodeBase64String(cipher.doFinal("encryptData".getBytes(StandardCharsets.UTF_8)));
|
||||
// System.out.println(a);
|
||||
//
|
||||
// String b = Base64.encodeBase64String(cipher.doFinal("encryptData".getBytes(StandardCharsets.UTF_8)));
|
||||
// System.out.println(a);
|
||||
//
|
||||
// String c = Base64.encodeBase64String(cipher.doFinal("encryptData".getBytes(StandardCharsets.UTF_8)));
|
||||
// System.out.println(a);
|
||||
//
|
||||
// String d = Base64.encodeBase64String(cipher.doFinal("encryptData".getBytes(StandardCharsets.UTF_8)));
|
||||
// System.out.println(a);
|
||||
// }
|
||||
} |
||||
@ -1 +1 @@ |
||||
# \u5F00\u542F\u5904\u65B9\u9884\u7ED3\u7B97\uFF08\u7B2C2\u5F00\u5173\uFF09\uFF08\u6CE8\u610F\u8BE5\u914D\u7F6E\u9700\u8054\u7CFBhis\u5F00\u53D1\u8005\u786E\u8BA4\u652F\u6301\u624D\u80FD\u5F00\u542F\uFF0C\u5426\u5219\u5B58\u5728\u98CE\u9669\uFF01\uFF09
his.is_recipe_prepay=false
# \u672C\u5730
#his.url=127.0.0.1:8888
# HIS\u662F\u5426\u5F00\u542F\u652F\u4ED8\u5B9D\u5206\u5F00\u5BF9\u8D26
his.is_ali_mer=false
# \u662F\u5426\u5F3A\u5236\u6253\u5370webservice\u7684xml\u8FD4\u56DE\u6570\u636E
his.is_log_resp=true
# \u5DDE\u50A3\u533B\u4F7F\u7528
his.is_req_cdata=false
# \u662F\u5426\u4F20\u9012openid\u7ED9his\u63A8\u9001\u6D88\u606F
his.is_push_msg=false
#-------------------------------
# \u6D4B\u8BD5\u73AF\u5883
his.dev_url=200.200.200.105:8888
# \u533B\u4FDD===========================
# \u65E7\u914D\u7F6E
his.md_url=127.0.0.1:7777
# \u5FAE\u4FE1\u533B\u4FDD
his.wx_med_url=10.20.10.7:7885
# \u652F\u4ED8\u5B9D\u533B\u4FDD
his.ali_med_url=10.20.10.7:7885
# \u6D4B\u8BD5============================================================
# \u516C\u53F8\u6D4B\u8BD5
#his.url=192.168.12.10:8888
# \u77F3\u6797\u53BF\u533B\u9662
#his.url=200.200.200.105:8888
# \u5FB7\u5B8F\u4E2D\u533B
#his.url=200.200.200.60:9999
# \u7EA2\u6CB3\u5DDE\u533B\u9662
his.url=10.20.10.6:8888
# \u8292\u5E02\u5987\u5E7C
#his.url=192.168.11.7:8888
# \u5B81\u8497\u5987\u5E7C
#his.url=172.19.3.15:8888
# \u5B81\u8497\u53BF\u533B\u9662
#his.url=192.168.10.8:8888
# \u516C\u53F8\u6D4B\u8BD5
#his.url=192.168.12.39:8888
#\u666F\u6D2A\u4E2D\u50A3\u533B
#his.url=192.168.197.217:8888
# \u516C\u53F8\u6D4B\u8BD5
#his.url=192.168.12.10:8888
# \u7EA2\u6CB3
#his.url=10.20.10.6:8888
# \u7EA2\u6CB3\u533B\u4FDD
#his.url=10.20.10.6:8888
#his.url=192.168.12.10:8888
#his.md_url=192.168.1.128:7885
#his.dev_url=10.20.10.6:9988
# \u6C38\u80DC
#his.url=200.200.200.20:8888
# \u5FB7\u5B8F\u4E2D\u533B
#his.url=200.200.200.60:8888
# \u534E\u576A
#his.url=192.168.1.115:8888
# \u8499\u81EA\u4E2D\u533B
#his.url=192.168.0.228:8888
# \u7389\u9F99
#his.url=192.168.0.17:8888
#
#his.url=172.16.10.15:8888
# \u7984\u529D\u949F\u7231
#his.url=200.200.200.5:8888
# \u8499\u81EA\u5E02\u4EBA\u6C11\u533B\u9662
#his.url=200.200.200.174:8080
# \u5143\u8C0B
#his.url=200.200.200.29:8888
# \u5143\u8C0B\u533B\u4FDD
#his.dev_url=200.200.200.36:9999
# \u8292\u5E02
#his.url=192.168.100.8:8888
# \u7EA2\u6CB3\u5987\u5E7C\u4FDD\u5065\u9662
#his.url=192.168.1.204:8888
# \u8292\u5E02\u5987\u5E7C
#his.url=192.168.11.7:8888
#
#his.url=10.10.11.23:8888
# \u77F3\u6797
#his.url=192.168.10.10:8888
# \u5BCC\u6C11
#his.url=200.200.201.27:8888
# \u897F\u53CC\u7248\u7EB3
#his.url=10.10.11.23:8888
#wx.password=ynxbd@6910 |
||||
# \u5F00\u542F\u5904\u65B9\u9884\u7ED3\u7B97\uFF08\u7B2C2\u5F00\u5173\uFF09\uFF08\u6CE8\u610F\u8BE5\u914D\u7F6E\u9700\u8054\u7CFBhis\u5F00\u53D1\u8005\u786E\u8BA4\u652F\u6301\u624D\u80FD\u5F00\u542F\uFF0C\u5426\u5219\u5B58\u5728\u98CE\u9669\uFF01\uFF09
his.is_recipe_prepay=false
# \u672C\u5730
#his.url=127.0.0.1:8888
# HIS\u662F\u5426\u5F00\u542F\u652F\u4ED8\u5B9D\u5206\u5F00\u5BF9\u8D26
his.is_ali_mer=false
# \u662F\u5426\u5F3A\u5236\u6253\u5370webservice\u7684xml\u8FD4\u56DE\u6570\u636E
his.is_log_resp=true
# \u5DDE\u50A3\u533B\u4F7F\u7528
his.is_req_cdata=false
# \u662F\u5426\u4F20\u9012openid\u7ED9his\u63A8\u9001\u6D88\u606F
his.is_push_msg=false
#-------------------------------
# \u6D4B\u8BD5\u73AF\u5883
his.dev_url=200.200.200.60:7777
# \u533B\u4FDD===========================
# \u65E7\u914D\u7F6E
his.md_url=127.0.0.1:7777
# \u5FAE\u4FE1\u533B\u4FDD
his.wx_med_url=10.20.10.7:7885
# \u652F\u4ED8\u5B9D\u533B\u4FDD
his.ali_med_url=10.20.10.7:7885
# \u6D4B\u8BD5============================================================
# \u516C\u53F8\u6D4B\u8BD5
#his.url=192.168.12.10:8888
# \u77F3\u6797\u53BF\u533B\u9662
#his.url=200.200.200.105:8888
# \u5FB7\u5B8F\u4E2D\u533B
his.url=200.200.200.60:7777
# \u7EA2\u6CB3\u5DDE\u533B\u9662
#his.url=10.20.10.6:8888
# \u8292\u5E02\u5987\u5E7C
#his.url=192.168.11.7:8888
# \u5B81\u8497\u5987\u5E7C
#his.url=172.19.3.15:8888
# \u5B81\u8497\u53BF\u533B\u9662
#his.url=192.168.10.8:8888
# \u516C\u53F8\u6D4B\u8BD5
#his.url=192.168.12.39:8888
#\u666F\u6D2A\u4E2D\u50A3\u533B
#his.url=192.168.197.217:8888
# \u516C\u53F8\u6D4B\u8BD5
#his.url=192.168.12.10:8888
# \u7EA2\u6CB3
#his.url=10.20.10.6:8888
# \u7EA2\u6CB3\u533B\u4FDD
#his.url=10.20.10.6:8888
#his.url=192.168.12.10:8888
#his.md_url=192.168.1.128:7885
#his.dev_url=10.20.10.6:9988
# \u6C38\u80DC
#his.url=200.200.200.20:8888
# \u5FB7\u5B8F\u4E2D\u533B
#his.url=200.200.200.60:8888
# \u534E\u576A
#his.url=192.168.1.115:8888
# \u8499\u81EA\u4E2D\u533B
#his.url=192.168.0.228:8888
# \u7389\u9F99
#his.url=192.168.0.17:8888
#
#his.url=172.16.10.15:8888
# \u7984\u529D\u949F\u7231
#his.url=200.200.200.5:8888
# \u8499\u81EA\u5E02\u4EBA\u6C11\u533B\u9662
#his.url=200.200.200.174:8080
# \u5143\u8C0B
#his.url=200.200.200.29:8888
# \u5143\u8C0B\u533B\u4FDD
#his.dev_url=200.200.200.36:9999
# \u8292\u5E02
#his.url=192.168.100.8:8888
# \u7EA2\u6CB3\u5987\u5E7C\u4FDD\u5065\u9662
#his.url=192.168.1.204:8888
# \u8292\u5E02\u5987\u5E7C
#his.url=192.168.11.7:8888
#
#his.url=10.10.11.23:8888
# \u77F3\u6797
#his.url=192.168.10.10:8888
# \u5BCC\u6C11
#his.url=200.200.201.27:8888
# \u897F\u53CC\u7248\u7EB3
#his.url=10.10.11.23:8888
#wx.password=ynxbd@6910 |
||||
Loading…
Reference in new issue