一、导入配置文件
csharp;gutter:true;
com.github.ulisesbocchio
jasypt-spring-boot-starter
3.0.4</p>
<pre><code>
### 二、执行测试:生成密文密码
> 1.加盐:在application.properties中添加(自行设置),加/解密规则
;gutter:true;
#加/解密的时候用这个密码
jasypt.encryptor.password=zhangzhixi
2.执行测试文件:用于生成密码
csharp;gutter:true;
import org.jasypt.encryption.StringEncryptor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;</p>
<p>/*<em>
* @ClassName com.zhixi.MyTest
* @Author zhangzhixi
* @Description
* @Date 2022-4-22 10:57
* @Version 1.0
</em>/
@SpringBootTest
public class MyTest {</p>
<pre><code>@Autowired
StringEncryptor stringEncryptor;
@Test
public void encryptorTest() {
/*你的数据库密码*/
String passwd = stringEncryptor.encrypt("you-passwd");
System.out.println("加密密码是:" + passwd);
System.out.println("解密密码是:"+stringEncryptor.decrypt(passwd));
}
</code></pre>
<p>}</p>
<pre><code>
> 3.将生成的密码添加到数据库连接信息中:注意要使用ENC()包裹住生成的密码
;gutter:true;
spring.datasource.password=ENC(LVwCic/f7N63bxiCWAoCq0IMOVjjGr69zalGkmbOaPVSz+k74hyVvdPLdBuo5)
4.删除加盐的规则
这个主要是防止别人看到你的加盐规则,可以得到你的密码。
三、启动项目
如果注释了加盐的规则,就需要在项目启动的时候做一些操作:
IDEA启动项目:
命令行下启动项目,加上参数:–jasypt.encryptor.password=xxx
Original: https://www.cnblogs.com/zhangzhixi/p/16178192.html
Author: Java小白的搬砖路
Title: SpringBoot下配置文件密码加密
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/612327/
转载文章受原作者版权保护。转载请注明原作者出处!