This commit is contained in:
ran.shang
2025-06-11 09:42:13 +08:00
commit 7e38b8d971
1935 changed files with 132836 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
package com.newyetai.common.util;
import org.jasypt.encryption.StringEncryptor;
import com.newyetai.common.exception.util.Assert;
import lombok.extern.slf4j.Slf4j;
/**
* 配置信息加解密工具
* @author sr on 2021-11-11
*/
@Slf4j
public class JasyptUtils {
private static StringEncryptor stringEncryptor;
public JasyptUtils(StringEncryptor stringEncryptor) {
Assert.isNull(JasyptUtils.stringEncryptor, "已存在加密对象");
JasyptUtils.stringEncryptor = stringEncryptor;
}
/**
* 加密
* @param str
* @return
* @author sr on 2021-11-11
*/
public static String encrypt(String str) {
try {
return stringEncryptor.encrypt(str);
} catch (Exception e) {
log.info("加密失败:", e);
return null;
}
}
/**
* 解密
* @param encodedStr
* @return
* @author sr on 2021-11-11
*/
public static String decrypt(String encodedStr) {
try {
return stringEncryptor.decrypt(encodedStr);
} catch (Exception e) {
log.info("解密失败:", e);
return null;
}
}
}