1.pom.xml引入jar包
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
2.yml文件中配置
jasypt:
encryptor:
password: nontaxZH
nontaxZH是salt(盐),可以根据自己需要来设置
3.新建一个test类
@SpringBootTest
@RunWith(SpringRunner.class)
public class PwdTest {
@Autowired
private StringEncryptor stringEncryptor;
@Test
public void test(){
String encrypt = stringEncryptor.encrypt("root");
System.out.println(encrypt);
}
}
其中 stringEncryptor.encrypt("root"); root是数据库密码,如果你的密码或要加密的配置参数是其他值,就填其他值。
按照以上新建test类完成后,启动该test,得到结果
加密完毕,可以启动application验证加密后是否可以连上数据库了~