2022-05-24 09:23:17 +08:00
|
|
|
|
package com.engine.salary.encrypt;
|
|
|
|
|
|
|
2022-10-10 09:43:57 +08:00
|
|
|
|
import com.engine.salary.sys.constant.SalarySysConstant;
|
|
|
|
|
|
import com.engine.salary.sys.entity.po.SalarySysConfPO;
|
|
|
|
|
|
import com.engine.salary.sys.enums.OpenEnum;
|
|
|
|
|
|
import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl;
|
2022-05-24 09:23:17 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import weaver.general.AES;
|
|
|
|
|
|
import weaver.general.BaseBean;
|
|
|
|
|
|
|
2022-10-10 09:43:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 此AES加密工具类仅用于关联应用设置中是否开启加密的应用使用
|
|
|
|
|
|
* 如另有需要,请重写工具类
|
|
|
|
|
|
*/
|
2022-05-24 09:23:17 +08:00
|
|
|
|
public class AESEncryptUtil {
|
|
|
|
|
|
|
2022-07-13 13:55:31 +08:00
|
|
|
|
static BaseBean bb = new BaseBean();
|
|
|
|
|
|
|
|
|
|
|
|
static String aesEncryptScrect = bb.getPropValue("hrmSalary", "AESEncryptScrect");
|
2022-10-10 09:43:57 +08:00
|
|
|
|
static SalarySysConfServiceImpl salarySysConfService = new SalarySysConfServiceImpl();
|
2022-07-13 13:55:31 +08:00
|
|
|
|
|
2022-05-24 09:23:17 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* AES加密
|
2022-07-13 13:55:31 +08:00
|
|
|
|
*
|
2022-05-24 09:23:17 +08:00
|
|
|
|
* @param source 原始数据
|
|
|
|
|
|
* @return 加密数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String encrypt(String source) {
|
2022-10-10 09:43:57 +08:00
|
|
|
|
String isEncrypt = getSalarySysConfigValue();
|
|
|
|
|
|
//防止二次加密
|
|
|
|
|
|
if (StringUtils.isNotBlank(source) && OpenEnum.OPEN.getValue().equals(isEncrypt) && !source.startsWith(SalarySysConstant.PRE_SIGN_ENCRYPT)) {
|
|
|
|
|
|
return SalarySysConstant.PRE_SIGN_ENCRYPT + AES.encrypt(source, aesEncryptScrect);
|
2022-05-24 09:23:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
return source;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-10 09:43:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 应用设置是否开启加密
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
private static String getSalarySysConfigValue() {
|
|
|
|
|
|
return salarySysConfService.getOneByCode(SalarySysConstant.OPEN_APPLICATION_ENCRYPT).getConfValue();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-24 09:23:17 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* AES解密
|
2022-07-13 13:55:31 +08:00
|
|
|
|
*
|
2022-05-24 09:23:17 +08:00
|
|
|
|
* @param encryptStr 加密字符串
|
|
|
|
|
|
* @return 解密字符串
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String decrypt(String encryptStr) {
|
2022-07-13 13:55:31 +08:00
|
|
|
|
if (StringUtils.isNotBlank(encryptStr)) {
|
2022-10-10 09:43:57 +08:00
|
|
|
|
if (encryptStr.startsWith(SalarySysConstant.PRE_SIGN_ENCRYPT)) {
|
|
|
|
|
|
encryptStr = encryptStr.substring(4, encryptStr.length());
|
|
|
|
|
|
}
|
2022-05-24 09:23:17 +08:00
|
|
|
|
return AES.decrypt(encryptStr, aesEncryptScrect);
|
|
|
|
|
|
}
|
|
|
|
|
|
return encryptStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-10 09:43:57 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 用于关闭加密设置后AES解密
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param encryptStr 加密字符串
|
|
|
|
|
|
* @return 解密字符串
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static String closeEncryptSetting(String encryptStr) {
|
|
|
|
|
|
if (StringUtils.isNotBlank(encryptStr) && encryptStr.startsWith(SalarySysConstant.PRE_SIGN_ENCRYPT)) {
|
|
|
|
|
|
encryptStr = encryptStr.substring(4, encryptStr.length());
|
|
|
|
|
|
return AES.decrypt(encryptStr, aesEncryptScrect);
|
|
|
|
|
|
}
|
2022-10-10 17:15:20 +08:00
|
|
|
|
if (StringUtils.isNotBlank(encryptStr) && encryptStr.length() == 16) {
|
|
|
|
|
|
return AES.decrypt(encryptStr, aesEncryptScrect);
|
|
|
|
|
|
}
|
2022-10-10 09:43:57 +08:00
|
|
|
|
return encryptStr;
|
|
|
|
|
|
}
|
2022-05-24 09:23:17 +08:00
|
|
|
|
}
|