Springboot 配置文件加密解密工具jasypt

pom.xml中引入依赖


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

配置文件中配置jasypt 加解密 密码,配置加密后的密文

jasypt:
  encryptor:
    password:  test

# spring security 配置
security:
  oauth2:
    client:
      client-id: ENC(KX34gPBBOaHwpxSXU0+KvA==)
      client-secret: ENC(KX34gPBBOaHwpxSXU0+KvA==)
      scope: server

测试工具

 public static void main(String[] args) {
        //对应配置文件中对应的根密码
        System.setProperty("jasypt.encryptor.password", "test");
        StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment());
        //加密方法
        System.out.println(stringEncryptor.encrypt("test"));
        //解密方法
        System.out.println(stringEncryptor.decrypt(stringEncryptor.encrypt("test")));
        //imENTO7M8bLO38LFSIxnzw==
        System.out.println(stringEncryptor.decrypt("KX34gPBBOaHwpxSXU0+KvA=="));

    }

 

你可能感兴趣的:(Springboot 配置文件加密解密工具jasypt)