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("roo