SpringBoot项目中如何利用application.yml文件配置数据库密码加密
作者:慢热型
时间:2023-05-12
浏览:4
使用@SpringBootApplication注解启动的项目,只需增加maven依赖我们对信息加解密是使用这个jar包的:编写加解密测试类:packagecn.linjk.ehome;importorg.jasypt.encryption.pbe.StandardPBEStringEncryptor;importorg.jasypt.encryption.pbe.config.EnvironmentPBEConfig;importorg.junit.Test;publicclassJasyptTest{
本文目录
使用@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({加密串})即可。

启动时需要配置 秘钥
将秘钥加入启动参数


作者最新文章
wps表格office打不开怎么办怎么解决
2026-11-03 10:00
ArchiveofOurOwn看文主页入口指南
2026-10-30 10:27
CorelDRAW转曲后如何修改:曲线节点编辑与轮廓调整教程
2026-10-30 09:53
QQ邮箱地址书写时括号能不能添加
2026-10-27 23:17
搭载 RTX 5070 12GB 显卡 联想 Legion 5i 15IAX11 游戏本海外发布
2026-10-26 16:26
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多
























