Python 官方文档:入门教程 => 点击学习
有时候因为安全问题,需要把配置文件的中数据库用户名密码由明文改成密文,大多数其实是为了应付甲方而已。 1.pom.xml引入依赖 <dependency> <
有时候因为安全问题,需要把配置文件的中数据库用户名密码由明文改成密文,大多数其实是为了应付甲方而已。
1.pom.xml引入依赖
<dependency>
<groupId>com.GitHub.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
2.自己想一个秘钥,然后弄一个main方法来测试和生成加密串,下面例子把“passWord”当做秘钥,加密 xiaoming 字符串。同样可以把加密的打印出来,放到解密里面去验证一下
//给配置文件加密
public static void main(String[] args) {
// 加密
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
//自己设置的秘钥
textEncryptor.setPassword("password");
String userName = textEncryptor.encrypt("xiaoming");
System.out.println(userName);
// 解密
BasicTextEncryptor textEncryptor2 = new BasicTextEncryptor();
textEncryptor2.setPassword("password");
String oldPassword = textEncryptor2.decrypt("avU0Q/XfNMXcGogowdcfLfB1FDdApc292pzeq8/uvrllChedBJvj4A==");
System.out.println(oldPassword);
System.out.println("--------------------------");
}
3.springboot配置文件 application.properties中添加配置
jasypt.encryptor.password=password
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@192.168.100.123:7029:base
spring.datasource.username=ENC(c31B0jWJp3EGFwqSkrUzhY//4CY/sO)
spring.datasource.password=ENC(+KUeW5dB03CxJYz9oVV2flbYW5xs1+)
要先声明秘钥,然后把刚main方法中加密出来的字符串替换原来的,注意一定要用ENC()把字符串包住才行。
然后重启就完事,就是这么简单。
到此这篇关于SpringBoot数据库配置文件明文密码加密解密的文章就介绍到这了,更多相关Springboot数据库密码加密解密内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: 关于Springboot数据库配置文件明文密码加密解密的问题
本文链接: https://www.lsjlt.com/news/143028.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0