您好,欢迎访问一九零五行业门户网

SpringBoot项目中如何利用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({加密串})即可。
启动时需要配置 秘钥
将秘钥加入启动参数
以上就是springboot项目中如何利用application.yml文件配置数据库密码加密的详细内容。
其它类似信息

推荐信息