【问题标题】:Jasypt not able to decrypt password from system environment variable with SpringJasypt 无法使用 Spring 从系统环境变量中解密密码
【发布时间】:2018-11-14 09:14:44
【问题描述】:

我有 jasypt 密码和 application.yml 中定义的加密密码,如下所示:

jasypt:
  encryptor:
    password: ${secretKey}

spring:
   datasource: 
       password: ENC(${password})

并为此使用@Value:

@Value("${spring.datasource.password}")
private String springPassword;

我已经在我的环境变量中定义了 secretKey 和密码。但是当我启动这个spring boot应用程序时,它会抛出错误:

Caused by: org.springframework.cache.Cache$ValueRetrievalException: Value for key 'spring.datasource.password' could not be loaded using 'com.ulisesbocchio.jasyptspringboot.caching.CachingDelegateEncryptablePropertySource$$Lambda$209/172678484@5ae15'

如果我对两个键都进行硬编码,那么它就可以正常工作了。

任何帮助将不胜感激。

【问题讨论】:

    标签: java spring spring-boot jasypt


    【解决方案1】:

    我有类似的问题。就我而言,原因是我在类路径上有 jasypt-1.9.2.jar 和 jasypt-1.9.4.jar。

    jasypt-1.9.4.jar 来自 jasypt-spring-boot 2.1.1 的依赖项。 jasypt-1.9.2.jar 来自 wss4j-ws-security-common 2.2.2 的依赖项。

    更改为 jasypt-spring-boot 2.1.0 解决了我的问题。

    【讨论】:

    • 我使用 maven 作为依赖处理程序并且没有依赖重叠..
    • Maven 无法解决依赖冲突,因为 jasypt 1.9.2 的 groupId='org.jasypt' 而 jasypt 1.9.4 的 groupId='com.melloware'。但是里面的类都在同一个包(org.jasypt...)中并且具有相同的名称。
    【解决方案2】:

    我知道为时已晚,但仍然如此。对我来说,将 ENC() 方法作为环境变量的一部分传递是有效的。

    jasypt:
      encryptor:
        password: ${secretKey}
    
    spring:
       datasource: 
           password: ${PASSWORD}
    

    设置环境变量时

    export PASSWORD=ENC(yourPassword)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 2016-04-17
      • 2018-07-12
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      相关资源
      最近更新 更多