Jasypt not able to decrypt password from system environment variable with Spring

Viewed 4398

I have jasypt password and the encrypted password defined in application.yml like this:

jasypt:
  encryptor:
    password: ${secretKey}

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

And using @Value for it:

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

I have defined both secretKey and password in my environment variable. But when I start this spring boot application, it throws error:

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'

If I hardcode both of the keys, than it's working fine.

Any help would be appreciated.

2 Answers

I had similar issue. The reason in my case was that I had jasypt-1.9.2.jar and jasypt-1.9.4.jar on the class path.

jasypt-1.9.4.jar came as dependency from jasypt-spring-boot 2.1.1. jasypt-1.9.2.jar came as dependency from wss4j-ws-security-common 2.2.2.

Changing to jasypt-spring-boot 2.1.0 solved the issue in my case.

I know it's too late but still. For me passing the ENC() method as part of environmental variable worked.

jasypt:
  encryptor:
    password: ${secretKey}

spring:
   datasource: 
       password: ${PASSWORD}

while setting environmental variable

export PASSWORD=ENC(yourPassword)
Related