SpringBoot项目application.yml文件数据库配置密码加密的方法
作者:辰小白 时间:2024-01-18 02:12:40
在Spring boot开发中,需要在application.yml文件里配置数据库的连接信息,或者在启动时传入数据库密码,如果不加密,传明文,数据库就直接暴露了,相当于"裸奔"了,因此需要进行加密处理才行。
使用@SpringBootApplication注解启动的项目,只需增加maven依赖
我们对信息加解密是使用这个jar包的:
编写加解密测试类:
package cn.linjk.ehome;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig;
import org.junit.Test;
public class JasyptTest {
@Test
public void testEncrypt() throws Exception {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
EnvironmentPBEConfig config = new EnvironmentPBEConfig();
config.setAlgorithm("PBEWithMD5AndDES"); // 加密的算法,这个算法是默认的
config.setPassword("test"); // 加密的密钥
standardPBEStringEncryptor.setConfig(config);
String plainText = "88888888";
String encryptedText = standardPBEStringEncryptor.encrypt(plainText);
System.out.println(encryptedText);
}
@Test
public void testDe() throws Exception {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
EnvironmentPBEConfig config = new EnvironmentPBEConfig();
config.setAlgorithm("PBEWithMD5AndDES");
config.setPassword("test");
standardPBEStringEncryptor.setConfig(config);
String encryptedText = "ip10XNIEfAMTGQLdqt87XnLRsshu0rf0";
String plainText = standardPBEStringEncryptor.decrypt(encryptedText);
System.out.println(plainText);
}
}
加密串拿到了,现在来修改application.yml的配置:
我们把加密串放在ENC({加密串})即可。
启动时需要配置 秘钥
将秘钥加入启动参数
来源:https://blog.csdn.net/qq493820798/article/details/104413098
标签:SpringBoot,application.yml,数据库加密
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python3中在Anaconda环境下安装basemap包
2021-11-30 20:05:57
![](https://img.aspxhome.com/file/2023/5/131525_0s.png)
Python 操作 PostgreSQL 数据库示例【连接、增删改查等】
2021-12-14 00:54:08
python 基于opencv 绘制图像轮廓
2023-07-11 05:47:54
![](https://img.aspxhome.com/file/2023/2/133452_0s.png)
BootStrop前端框架入门教程详解
2024-04-29 13:46:10
![](https://img.aspxhome.com/file/2023/7/132537_0s.png)
python中强大的format函数实例详解
2022-02-19 18:47:10
IEEE Spectrum 2014编程语言排行榜
2023-03-21 16:38:06
![](https://img.aspxhome.com/file/2023/0/130930_0s.png)
asp函数判断服务器是否安装了某种组件
2008-10-11 14:45:00
异步加载Google Adsense 更新到Wordpress 2.62
2008-09-11 13:09:00
Go语言区别于其他语言的特性
2023-06-26 02:52:10
html注释书写规范
2008-08-13 13:06:00
学点简单的Django之第一个Django程序的实现
2021-03-23 05:10:59
![](https://img.aspxhome.com/file/2023/9/92449_0s.png)
Python实现动态加载模块、类、函数的方法分析
2022-07-25 22:48:58
用Python实现数据筛选与匹配实例
2023-01-13 15:31:42
![](https://img.aspxhome.com/file/2023/1/112411_0s.jpg)
Go语言中日期包(time包)的具体使用
2024-05-08 10:52:33
![](https://img.aspxhome.com/file/2023/1/127361_0s.jpg)
python的格式化输出(format,%)实例详解
2022-03-20 04:17:57
MySQL之复杂查询的实现
2024-01-23 00:32:43
![](https://img.aspxhome.com/file/2023/8/122928_0s.jpg)
SQL Server误区30日谈 第21天 数据损坏可以通过重启SQL Server来修复
2024-01-23 01:53:48
ZABBIX3.2使用python脚本实现监控报表的方法
2021-04-11 20:15:02
![](https://img.aspxhome.com/file/2023/0/79680_0s.jpg)
SQLSERVER全文目录全文索引的使用方法和区别讲解
2024-01-12 18:12:28
![](https://img.aspxhome.com/file/2023/8/106248_0s.jpg)
Python调用百度AI实现图片上文字识别功能实例
2022-07-27 11:02:44
![](https://img.aspxhome.com/file/2023/8/72188_0s.png)