04 Apr 2018

Spring Properties Encryption using “jasypt-spring-boot” Dependency

11:59 AM java, MongoDB 0 Comment

We should encrypt some sensitive properties like password in real time projects to avoid hacking.

Here we are using  jasypt-spring-boot dependency with spring boot project to encrypt properties and use those properties in code.

Below are the dependencies for different build tools:

Maven:

Gradle:

application.properties:

The example application.properties file in spring boot application look like as following

As you can see, spring.data.mongodb.password value is encrypted. But how was this generated?

We can generate it by using jasypt like below (:

Usage:

We can use spring.data.mongodb.password property in any spring component as like using any other properties.

Example:

Running the Application:

when running the application we should provide the value which is used to generate encrypted password i:e, myEncPwd.

 

Thank You 🙂

Leave a Reply