fix: 修复数据源加密key不一致的问题

This commit is contained in:
taojinlong
2026-03-18 17:22:36 +08:00
committed by tjlygdx
parent 809d32c20f
commit 49d73e1e1d
3 changed files with 11 additions and 4 deletions

View File

@@ -102,6 +102,10 @@
<key-type>java.lang.String</key-type>
<value-type>java.lang.Object</value-type>
</cache>
<cache alias="de_ds_symmetricKey" uses-template="common-cache">
<key-type>java.lang.String</key-type>
<value-type>java.lang.String</value-type>
</cache>
<cache alias="de_v2_user_token_cache">
<key-type>java.lang.String</key-type>

View File

@@ -9,6 +9,7 @@ public class CacheConstant {
public static final String USER_BUSI_PERS_CACHE = "de_v2_user_busi_pers";
public static final String USER_BUSI_PERS_INTERACTIVE_CACHE = "de_v2_user_busi_pers_interactive";
public static final String USER_COMMUNITY_LANGUAGE = "de_v2_user_community_language";
public static final String Symmetric_Key = "de_ds_symmetricKey";
}
public static class RoleCacheConstant {

View File

@@ -23,6 +23,8 @@ import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import static io.dataease.constant.CacheConstant.UserCacheConstant.Symmetric_Key;
@Component
public class RsaUtils {
@@ -205,19 +207,19 @@ public class RsaUtils {
private static final String ALGORITHM = "AES";
public static String symmetricKey = null;
public static String symmetricKey = "symmetricKey";
private static final int KEY_SIZE = 128;
public static String generateSymmetricKey() {
try {
if (StringUtils.isEmpty(symmetricKey)) {
if (!CacheUtils.keyExist(Symmetric_Key, symmetricKey)) {
KeyGenerator keyGenerator = KeyGenerator.getInstance(ALGORITHM);
keyGenerator.init(KEY_SIZE, new SecureRandom());
SecretKey secretKey = keyGenerator.generateKey();
symmetricKey = Base64.getEncoder().encodeToString(secretKey.getEncoded());
CacheUtils.put(Symmetric_Key, symmetricKey, Base64.getEncoder().encodeToString(secretKey.getEncoded()));
}
return symmetricKey;
return CacheUtils.get(Symmetric_Key, symmetricKey).toString();
} catch (Exception e) {
throw new RuntimeException(e);
}