Is there a way to use Spring Cloud {cipher} in Spring Boot application config?

Brian Abston picture Brian Abston · Feb 10, 2015 · Viewed 18.3k times · Source

I have a Spring Boot app that is using Spring Cloud Config but I would like to encrypt the Spring Cloud Config password in the Spring Boot apps bootstrap.yml file. Is there a way to do this? Below is an example.

Spring Boot app bootstrap.yml

spring:
  cloud:
    config:
      uri: http://locahost:8888
      username: user
      password: '{cipher}encryptedpassword'

Answer

Ken Krueger picture Ken Krueger · May 20, 2015

A couple things I've discovered related to this.

If you use bootstrap.yml (or application.yml), the format for the cipher text must enclosed within single quotes:

security.user.password: '{cipher}56e611ce4a99ffd99908d2c9aa1461d831722812e4370a5b6900b7ea680ae914'  

If you use bootstrap.properties (or application.properties), the format for the cipher text must NOT be enclosed:

security.user.password= {cipher}56e611ce4a99ffd99908d2c9aa1461d831722812e4370a5b6900b7ea680ae914

The [reference docs][1] show the yml without the quotes, which I never got to work. SnakeYaml always reported an error:

"expected <block end>, but found Scalar"