配置文件加密
在生产环境中,我们不可能直接将密码等信息以明文的方式进行配置,如何使用配置文件加密?
pom
<!--配置文件加解密-->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
</dependency>
生产密文
@Test
public void test1(){
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
//加密所需的salt
textEncryptor.setPassword("yunho_hudn");
//要加密的数据(数据库的用户名或密码)
String username = textEncryptor.encrypt("root");
String password = textEncryptor.encrypt("123456");
System.out.println("username:"+username);
System.out.println("password:"+password);
}
配置密文
spring:
# 配置Sa-Token单独使用的Redis连接 (此处需要和SSO-Server端连接同一个Redis)
redis:
# Redis数据库索引
database: 6
# Redis服务器地址
host: hudn-redis
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码(默认为空)
password: ENC(tPNcWEzNkIte5pKneqxhdw==)
# 连接超时时间(毫秒)
timeout: 30ms
lettuce:
pool:
# 连接池最大连接数
max-active: 200
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms
# 连接池中的最大空闲连接
max-idle: 10
# 连接池中的最小空闲连接
min-idle: 0
配置密钥
两种方式:
直接在配置文件中配置,这种方式不推荐,如果这么做了其实配置文件加密也形同虚设了
jasypt.encryptor.password=123456
在执行文件中添加对应参数
-Djasypt.encryptor.password=123456
原文始发于微信公众号(云户):配置文件加密
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/35233.html