Secrets in spring boot applications

Taken from:

If using @SpringBootApplication

maven

<dependency>
        <groupId>com.github.ulisesbocchio</groupId>
        <artifactId>jasypt-spring-boot-starter</artifactId>
        <version>2.1.0</version>
</dependency>

Properties files

jasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD:}
my.secret=ENC(p5XGoOYt4xjYAVs7aCzxtmF+9Ab0uFpT)

Encrypting your password

java -cp ~/.m2/repository/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI password=${JASYPT_ENCRYPTOR_PASSWORD} input="mySecret"


----ENVIRONMENT-----------------

Runtime: Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.131-b11



----ARGUMENTS-------------------

input: mySecret
password: mypassword



----OUTPUT----------------------

p5XGoOYt4xjYAVs7aCzxtmF+9Ab0uFpT

Code - using the value

@Value("${my.secret}") String mySecret

Last updated