1,依赖:
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
2,配置秘钥:
# 配置加密密钥
jasypt:
encryptor:
password: zhengqing # TODO 这里密钥修改为自己的!!!
3,jasypt加密/解密测试类
public class JasyptTest {
@Test
public void test() {
// 对应配置文件中配置的加密密钥
System.setProperty("jasypt.encryptor.password", "zhengqing");
StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment());
System.out.println("加密: " + stringEncryptor.encrypt("root"));
System.out.println("解密: " + stringEncryptor.decrypt("N/+f2B9SznK4MUDSp24Upw=="));
}
}
demo:https://gitee.com/zhengqingya/java-workspace
双数据源demo:https://github.com/liangbintao/springboot_datasources