修改:配置加密&解密密钥初始化方式优化
This commit is contained in:
@@ -1 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.approve.config.DecryptEnvironmentPostProcessor
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.sdm.capability.config;
|
||||
|
||||
import com.sdm.common.utils.AESUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class DecryptEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Properties props = new Properties(); // 临时存储需要替换的配置
|
||||
// 假设加密密码前缀为 "ENC(",后缀为 ")"
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
for (PropertySource<?> propertySource : propertySources) {
|
||||
if (propertySource instanceof EnumerablePropertySource) {
|
||||
EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
|
||||
String[] propertyNames = enumerablePropertySource.getPropertyNames();
|
||||
// 遍历所有配置key:value
|
||||
for (String propertyName : propertyNames) {
|
||||
String propertyVal = environment.getProperty(propertyName);
|
||||
// 根据自己写的规则来解析那些配置是需要解密的
|
||||
if (propertyVal != null && propertyVal.startsWith("ENC(") && propertyVal.endsWith(")")) {
|
||||
// 解析得到加密的数据
|
||||
String encryptedValue = propertyVal.substring(4, propertyVal.length() - 1);
|
||||
// 调用自定义工具类解密
|
||||
String decryptedValue = null;
|
||||
try {
|
||||
decryptedValue = AESUtil.decode(encryptedValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 保存需要替换的配置
|
||||
props.put(propertyName, decryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加解密后的属性到环境中
|
||||
if (!props.isEmpty()) {
|
||||
PropertiesPropertySource pps = new PropertiesPropertySource("decryptedProperties", props);
|
||||
environment.getPropertySources().addFirst(pps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.capability.config.DecryptEnvironmentPostProcessor
|
||||
@@ -42,7 +42,7 @@ fi
|
||||
echo "正在启动项目..."
|
||||
|
||||
# 启动项目,保留控制台输出
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5001 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5001 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ fi
|
||||
echo "正在启动项目..."
|
||||
|
||||
# 启动项目,保留控制台输出
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5001 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5001 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sdm.approve.config;
|
||||
package com.sdm.common.config;
|
||||
|
||||
import com.sdm.common.utils.AESUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.*;
|
||||
@@ -28,11 +29,20 @@ public class DecryptEnvironmentPostProcessor implements EnvironmentPostProcessor
|
||||
String encryptedValue = propertyVal.substring(4, propertyVal.length() - 1);
|
||||
// 调用自定义工具类解密
|
||||
String decryptedValue = null;
|
||||
Long t1 = System.currentTimeMillis();
|
||||
// 优先读取JVM参数,然后环境变量参数,没有就报错
|
||||
String spdmEnkey = StringUtils.isBlank(System.getProperty("spdm.enkey"))?
|
||||
System.getenv("spdm.enkey"):System.getProperty("spdm.enkey");
|
||||
if(StringUtils.isBlank(spdmEnkey)){
|
||||
throw new RuntimeException("spdm加密配置密钥读取失败!");
|
||||
}
|
||||
try {
|
||||
decryptedValue = AESUtil.decode(encryptedValue);
|
||||
decryptedValue = AESUtil.decodeNew(encryptedValue,spdmEnkey);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Long t2 = System.currentTimeMillis();
|
||||
System.out.println("解密耗时: " + (t2 - t1) + "ms");
|
||||
// 保存需要替换的配置
|
||||
props.put(propertyName, decryptedValue);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sdm.common.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -17,13 +18,14 @@ import java.util.Base64;
|
||||
@Component
|
||||
public class AESUtil {
|
||||
|
||||
private static final String FINAL_PARAM = "XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c=";
|
||||
// private static final String FINAL_PARAM = "XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c=";
|
||||
|
||||
/**
|
||||
* 块大小固定为8字节
|
||||
*/
|
||||
private final static String AES_CBC_PKCS5PADDING = "AES/ECB/PKCS5Padding";
|
||||
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
@@ -31,8 +33,8 @@ public class AESUtil {
|
||||
* @return 密文
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encode(String content) throws Exception {
|
||||
byte[] key = Base64.getDecoder().decode(FINAL_PARAM);
|
||||
public static String encodeNew(String content,String keyStr) throws Exception {
|
||||
byte[] key = Base64.getDecoder().decode(keyStr);
|
||||
byte[] data = content.getBytes();
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
@@ -40,6 +42,7 @@ public class AESUtil {
|
||||
return Base64.getEncoder().encodeToString(cipher.doFinal(data));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
@@ -47,8 +50,8 @@ public class AESUtil {
|
||||
* @return 解密后的数据
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decode(String content) throws Exception {
|
||||
byte[] key = Base64.getDecoder().decode(FINAL_PARAM);
|
||||
public static String decodeNew(String content,String keyStr) throws Exception {
|
||||
byte[] key = Base64.getDecoder().decode(keyStr);
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
|
||||
@@ -71,17 +74,6 @@ public class AESUtil {
|
||||
return keyGenerator.generateKey();
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// try {
|
||||
// String ret = encode("03BD691EB0264CECF79");
|
||||
// System.out.println("encode:" + ret);
|
||||
// String raw = decode(ret);
|
||||
// System.out.println("decode:" + raw);
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* get Cipher
|
||||
*
|
||||
@@ -211,4 +203,23 @@ public class AESUtil {
|
||||
}
|
||||
return cipherText;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 优先读取JVM参数,然后环境变量参数,没有就报错
|
||||
String spdmEnkey = StringUtils.isBlank(System.getProperty("spdm.enkey"))?
|
||||
System.getenv("spdm.enkey"):System.getProperty("spdm.enkey");
|
||||
if(StringUtils.isBlank(spdmEnkey)){
|
||||
throw new RuntimeException("spdm加密配置密钥读取失败!");
|
||||
}
|
||||
System.out.println("密钥是:"+spdmEnkey);
|
||||
String ret = encodeNew("我是原文:8899",spdmEnkey);
|
||||
System.out.println("encode:" + ret);
|
||||
String raw = decodeNew(ret,spdmEnkey);
|
||||
System.out.println("decode:" + raw);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1
common/src/main/resources/META-INF/spring.factories
Normal file
1
common/src/main/resources/META-INF/spring.factories
Normal file
@@ -0,0 +1 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.common.config.DecryptEnvironmentPostProcessor
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.sdm.data.config;
|
||||
|
||||
import com.sdm.common.utils.AESUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class DecryptEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Properties props = new Properties(); // 临时存储需要替换的配置
|
||||
// 假设加密密码前缀为 "ENC(",后缀为 ")"
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
for (PropertySource<?> propertySource : propertySources) {
|
||||
if (propertySource instanceof EnumerablePropertySource) {
|
||||
EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
|
||||
String[] propertyNames = enumerablePropertySource.getPropertyNames();
|
||||
// 遍历所有配置key:value
|
||||
for (String propertyName : propertyNames) {
|
||||
String propertyVal = environment.getProperty(propertyName);
|
||||
// 根据自己写的规则来解析那些配置是需要解密的
|
||||
if (propertyVal != null && propertyVal.startsWith("ENC(") && propertyVal.endsWith(")")) {
|
||||
// 解析得到加密的数据
|
||||
String encryptedValue = propertyVal.substring(4, propertyVal.length() - 1);
|
||||
// 调用自定义工具类解密
|
||||
String decryptedValue = null;
|
||||
try {
|
||||
decryptedValue = AESUtil.decode(encryptedValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 保存需要替换的配置
|
||||
props.put(propertyName, decryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加解密后的属性到环境中
|
||||
if (!props.isEmpty()) {
|
||||
PropertiesPropertySource pps = new PropertiesPropertySource("decryptedProperties", props);
|
||||
environment.getPropertySources().addFirst(pps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.data.config.DecryptEnvironmentPostProcessor
|
||||
@@ -42,4 +42,4 @@ fi
|
||||
|
||||
# 启动项目
|
||||
echo "正在启动项目..."
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5002 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5002 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
@@ -42,4 +42,4 @@ fi
|
||||
|
||||
# 启动项目
|
||||
echo "正在启动项目..."
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5002 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5002 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
@@ -42,4 +42,4 @@ fi
|
||||
|
||||
# 启动项目
|
||||
echo "正在启动项目..."
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5003 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5003 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
@@ -42,4 +42,4 @@ fi
|
||||
|
||||
# 启动项目
|
||||
echo "正在启动项目..."
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5003 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5003 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
@@ -43,6 +43,6 @@ fi
|
||||
|
||||
# 启动项目
|
||||
echo "正在启动项目..."
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,6 @@ fi
|
||||
|
||||
# 启动项目
|
||||
echo "正在启动项目..."
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.sdm.pbs.config;
|
||||
|
||||
import com.sdm.common.utils.AESUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class DecryptEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Properties props = new Properties(); // 临时存储需要替换的配置
|
||||
// 假设加密密码前缀为 "ENC(",后缀为 ")"
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
for (PropertySource<?> propertySource : propertySources) {
|
||||
if (propertySource instanceof EnumerablePropertySource) {
|
||||
EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
|
||||
String[] propertyNames = enumerablePropertySource.getPropertyNames();
|
||||
// 遍历所有配置key:value
|
||||
for (String propertyName : propertyNames) {
|
||||
String propertyVal = environment.getProperty(propertyName);
|
||||
// 根据自己写的规则来解析那些配置是需要解密的
|
||||
if (propertyVal != null && propertyVal.startsWith("ENC(") && propertyVal.endsWith(")")) {
|
||||
// 解析得到加密的数据
|
||||
String encryptedValue = propertyVal.substring(4, propertyVal.length() - 1);
|
||||
// 调用自定义工具类解密
|
||||
String decryptedValue = null;
|
||||
try {
|
||||
decryptedValue = AESUtil.decode(encryptedValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 保存需要替换的配置
|
||||
props.put(propertyName, decryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加解密后的属性到环境中
|
||||
if (!props.isEmpty()) {
|
||||
PropertiesPropertySource pps = new PropertiesPropertySource("decryptedProperties", props);
|
||||
environment.getPropertySources().addFirst(pps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.pbs.config.DecryptEnvironmentPostProcessor
|
||||
@@ -42,4 +42,4 @@ fi
|
||||
|
||||
# 启动项目
|
||||
echo "正在启动项目..."
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5004 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5004 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
@@ -42,4 +42,4 @@ fi
|
||||
|
||||
# 启动项目
|
||||
echo "正在启动项目..."
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5004 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5004 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.sdm.performance.config;
|
||||
|
||||
import com.sdm.common.utils.AESUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class DecryptEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Properties props = new Properties(); // 临时存储需要替换的配置
|
||||
// 假设加密密码前缀为 "ENC(",后缀为 ")"
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
for (PropertySource<?> propertySource : propertySources) {
|
||||
if (propertySource instanceof EnumerablePropertySource) {
|
||||
EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
|
||||
String[] propertyNames = enumerablePropertySource.getPropertyNames();
|
||||
// 遍历所有配置key:value
|
||||
for (String propertyName : propertyNames) {
|
||||
String propertyVal = environment.getProperty(propertyName);
|
||||
// 根据自己写的规则来解析那些配置是需要解密的
|
||||
if (propertyVal != null && propertyVal.startsWith("ENC(") && propertyVal.endsWith(")")) {
|
||||
// 解析得到加密的数据
|
||||
String encryptedValue = propertyVal.substring(4, propertyVal.length() - 1);
|
||||
// 调用自定义工具类解密
|
||||
String decryptedValue = null;
|
||||
try {
|
||||
decryptedValue = AESUtil.decode(encryptedValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 保存需要替换的配置
|
||||
props.put(propertyName, decryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加解密后的属性到环境中
|
||||
if (!props.isEmpty()) {
|
||||
PropertiesPropertySource pps = new PropertiesPropertySource("decryptedProperties", props);
|
||||
environment.getPropertySources().addFirst(pps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.performance.config.DecryptEnvironmentPostProcessor
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.sdm.project.config;
|
||||
|
||||
import com.sdm.common.utils.AESUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class DecryptEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Properties props = new Properties(); // 临时存储需要替换的配置
|
||||
// 假设加密密码前缀为 "ENC(",后缀为 ")"
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
for (PropertySource<?> propertySource : propertySources) {
|
||||
if (propertySource instanceof EnumerablePropertySource) {
|
||||
EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
|
||||
String[] propertyNames = enumerablePropertySource.getPropertyNames();
|
||||
// 遍历所有配置key:value
|
||||
for (String propertyName : propertyNames) {
|
||||
String propertyVal = environment.getProperty(propertyName);
|
||||
// 根据自己写的规则来解析那些配置是需要解密的
|
||||
if (propertyVal != null && propertyVal.startsWith("ENC(") && propertyVal.endsWith(")")) {
|
||||
// 解析得到加密的数据
|
||||
String encryptedValue = propertyVal.substring(4, propertyVal.length() - 1);
|
||||
// 调用自定义工具类解密
|
||||
String decryptedValue = null;
|
||||
try {
|
||||
decryptedValue = AESUtil.decode(encryptedValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 保存需要替换的配置
|
||||
props.put(propertyName, decryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加解密后的属性到环境中
|
||||
if (!props.isEmpty()) {
|
||||
PropertiesPropertySource pps = new PropertiesPropertySource("decryptedProperties", props);
|
||||
environment.getPropertySources().addFirst(pps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.project.config.DecryptEnvironmentPostProcessor
|
||||
@@ -42,4 +42,4 @@ fi
|
||||
echo "正在启动项目... "
|
||||
|
||||
# 启动项目并保留控制台输出
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
@@ -42,4 +42,4 @@ fi
|
||||
echo "正在启动项目... "
|
||||
|
||||
# 启动项目并保留控制台输出
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.sdm.system.config;
|
||||
|
||||
import com.sdm.common.utils.AESUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class DecryptEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Properties props = new Properties(); // 临时存储需要替换的配置
|
||||
// 假设加密密码前缀为 "ENC(",后缀为 ")"
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
for (PropertySource<?> propertySource : propertySources) {
|
||||
if (propertySource instanceof EnumerablePropertySource) {
|
||||
EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
|
||||
String[] propertyNames = enumerablePropertySource.getPropertyNames();
|
||||
// 遍历所有配置key:value
|
||||
for (String propertyName : propertyNames) {
|
||||
String propertyVal = environment.getProperty(propertyName);
|
||||
// 根据自己写的规则来解析那些配置是需要解密的
|
||||
if (propertyVal != null && propertyVal.startsWith("ENC(") && propertyVal.endsWith(")")) {
|
||||
// 解析得到加密的数据
|
||||
String encryptedValue = propertyVal.substring(4, propertyVal.length() - 1);
|
||||
// 调用自定义工具类解密
|
||||
String decryptedValue = null;
|
||||
try {
|
||||
decryptedValue = AESUtil.decode(encryptedValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 保存需要替换的配置
|
||||
props.put(propertyName, decryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加解密后的属性到环境中
|
||||
if (!props.isEmpty()) {
|
||||
PropertiesPropertySource pps = new PropertiesPropertySource("decryptedProperties", props);
|
||||
environment.getPropertySources().addFirst(pps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.system.config.DecryptEnvironmentPostProcessor
|
||||
@@ -42,5 +42,5 @@ fi
|
||||
echo "正在启动项目..."
|
||||
|
||||
# 启动项目,保留控制台输出
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5006 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5006 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
|
||||
@@ -42,5 +42,5 @@ fi
|
||||
echo "正在启动项目..."
|
||||
|
||||
# 启动项目,保留控制台输出
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5006 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5006 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.sdm.task.config;
|
||||
|
||||
import com.sdm.common.utils.AESUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Component
|
||||
public class DecryptEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Properties props = new Properties(); // 临时存储需要替换的配置
|
||||
// 假设加密密码前缀为 "ENC(",后缀为 ")"
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
for (PropertySource<?> propertySource : propertySources) {
|
||||
if (propertySource instanceof EnumerablePropertySource) {
|
||||
EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
|
||||
String[] propertyNames = enumerablePropertySource.getPropertyNames();
|
||||
// 遍历所有配置key:value
|
||||
for (String propertyName : propertyNames) {
|
||||
String propertyVal = environment.getProperty(propertyName);
|
||||
// 根据自己写的规则来解析那些配置是需要解密的
|
||||
if (propertyVal != null && propertyVal.startsWith("ENC(") && propertyVal.endsWith(")")) {
|
||||
// 解析得到加密的数据
|
||||
String encryptedValue = propertyVal.substring(4, propertyVal.length() - 1);
|
||||
// 调用自定义工具类解密
|
||||
String decryptedValue = null;
|
||||
try {
|
||||
decryptedValue = AESUtil.decode(encryptedValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 保存需要替换的配置
|
||||
props.put(propertyName, decryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 添加解密后的属性到环境中
|
||||
if (!props.isEmpty()) {
|
||||
PropertiesPropertySource pps = new PropertiesPropertySource("decryptedProperties", props);
|
||||
environment.getPropertySources().addFirst(pps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=com.sdm.task.config.DecryptEnvironmentPostProcessor
|
||||
@@ -43,5 +43,5 @@ echo "正在启动项目..."
|
||||
echo "======================================================================"
|
||||
|
||||
# 启动项目,保留控制台输出
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5007 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-190 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5007 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
|
||||
@@ -43,5 +43,5 @@ echo "正在启动项目..."
|
||||
echo "======================================================================"
|
||||
|
||||
# 启动项目,保留控制台输出
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5007 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
nohup java ${JVM_OPTS} -Dspring.profiles.active=dev-65 -Dspdm.enkey=XzKRqYnUypdE8VJ41yo/i0rMpZ0IlztSZ1PqWhr0q/c= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5007 -jar "${FULL_JAR_PATH}" > "${LOG_FILE}" 2>&1 &
|
||||
|
||||
|
||||
Reference in New Issue
Block a user