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({加密串})即可。

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


作者最新文章
漫蛙manwa漫画链接分享及官网指南
2026-11-21 10:11
Opera欧朋浏览器垂直标签栏怎么开启 三种入口设置步骤
2026-11-20 14:10
AO3官网镜像链接一键跳转-手机入口快速访问
2026-11-19 15:27
AO3镜像站入口及官网导航链接
2026-11-18 11:01
WPS的Excel用Office打开无法显示照片
2026-11-08 14:31
热门文章
更多
精品专题
更多
Mac软件
更多
火山引擎 网页版
Windows/ macOS/ Linux
火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。








