springboot整合jasypt加密yml配置文件及双数据源demo

1,依赖:


    com.github.ulisesbocchio
    jasypt-spring-boot-starter
    2.1.0

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=="));
    }
}

[参考]:https://blog.csdn.net/qq_38225558/article/details/105747906?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-7.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-7.nonecase

demo:https://gitee.com/zhengqingya/java-workspace

双数据源demo:https://github.com/liangbintao/springboot_datasources

你可能感兴趣的:(springboot整合jasypt加密yml配置文件及双数据源demo)