Include the jar by adding below line in gradle.build
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:1.2'
Download the latest Jasypt from java2s.com
http://www.java2s.com/Code/Jar/j/Downloadjasypt190jar.htm
List of algorithm supported by JASYPT
http://www.jasypt.org/cli.html#Listing_algorithms
Encrypt and Decrypt a password using JASYPT
Encryption command:
java -cp jasypt-1.9.0.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="tyson" password=SimplePassword algorithm=PBEWithMD5AndDES
Decryption command:
java -cp jasypt-1.9.0.jar org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI input="encryptedkey" password=SimplePassword Algoalgorithm=PBEWithMD5AndDES
You can add key in application properties as
jasypt.encryptor.password=SimplePassword
or you can also give it on runtime
-Djasypt.encryptor.password=SimplePassword
application.properties entry for JASYPT
jasypt.encryptor.password=SimplePassword jasypt.encryptor.algorithm=PBEWithMD5AndDES
Possible other properties :
jasypt.encryptor.key-obtention-iterations= jasypt.encryptor.pool-size= jasypt.encryptor.provider-name= jasypt.encryptor.provider-class-name= jasypt.encryptor.salt-generator-classname= jasypt.encryptor.iv-generator-classname= jasypt.encryptor.string-output-type=
Logs of JASYPT on application starting :
O 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor 2020-04-04 23:31:39.427 INFO 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : Encryptor config not found for property jasypt.encryptor.algorithm, using default value: PBEWITHHMACSHA512ANDAES_256 2020-04-04 23:31:39.428 INFO 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : Encryptor config not found for property jasypt.encryptor.key-obtention-iterations, using default value: 1000 2020-04-04 23:31:39.429 INFO 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : Encryptor config not found for property jasypt.encryptor.pool-size, using default value: 1 2020-04-04 23:31:39.430 INFO 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : Encryptor config not found for property jasypt.encryptor.provider-name, using default value: null 2020-04-04 23:31:39.431 INFO 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : Encryptor config not found for property jasypt.encryptor.provider-class-name, using default value: null 2020-04-04 23:31:39.432 INFO 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : Encryptor config not found for property jasypt.encryptor.salt-generator-classname, using default value: org.jasypt.salt.RandomSaltGenerator 2020-04-04 23:31:39.434 INFO 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : Encryptor config not found for property jasypt.encryptor.iv-generator-classname, using default value: org.jasypt.iv.RandomIvGenerator 2020-04-04 23:31:39.436 INFO 29600 --- [ main] c.u.j.encryptor.DefaultLazyEncryptor : Encryptor config not found for property jasypt.encryptor.string-output-type, using default value: base64 2020-04-04 23:31:39.692 WARN 29600 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app': Unsatisfied dependency expressed through field 'dataSource'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Unsatisfied dependency expressed through method 'dataSource' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties' : prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.password' to java.lang.String 2020-04-04 23:31:39.698 INFO 29600 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]