微服务项目配置文件参数安全方案
项目环境
- springboot系列项目
- maven依赖管理
- 任意配置中心(apollo/配置文件/k8s ConfigMap Secrets)
项目代码添加依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>${version}</version>
</dependency>
配置文件添加盐值
jasypt.encryptor.password = password
加密参数生成
//即为jasypt加密时使用的密码 jasypt.encryptor.password=test
private static final String soltPassWord = "test";
private static final String dbPassWord = "123456";
//即为参数配置时加密的密码 例如 db.password= ENC(ab/quILuP+CtWffG+lJyHQ==)
private static final String encPassword = "ab/quILuP+CtWffG+lJyHQ==";
public static void main(String[] args) {
// 加密时使用的密码
BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
basicTextEncryptor.setPassword(soltPassWord);
String encrypt = basicTextEncryptor.encrypt(dbPassWord);
System.out.println("加密后的:"+encrypt);
BasicTextEncryptor basicTextEncryptor1 = new BasicTextEncryptor();
basicTextEncryptor1.setPassword(soltPassWord);
String decrypt = basicTextEncryptor1.decrypt(encPassword);
System.out.println("解密后的:"+decrypt);
}
加密参数值填写
#自定义前后缀
#jasypt.encryptor.property.prefix=ENC@[
#jasypt.encryptor.property.suffix=]
db.password= ENC(8dcdhff0dffdj)
参考资料
本文来自博客园,作者:梦回大唐meng,转载请注明原文链接:https://www.cnblogs.com/BitX/p/18303240
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?