I have an application with encrypted password for database connection, but when I want to run it with the secret key in maven options it doesn't work. I have added the jasypt plugin in the pom.xml.
The command I run:
mvn -Djasypt.encryptor.password=foo spring-boot:run
application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/my_database
spring.datasource.username=root
spring.datasource.password=ENC(Hu76tW6HJjEp730PNXSFOQ==)
jasypt.encryptor.algorithm=PBEWithMD5AndDES
jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator
When I provide the secret key in the application.properties file, it does work.
The command I run when the secret key is provided:
mvn spring-boot:run
application.properties when the secret key is provided:
spring.datasource.url=jdbc:mysql://localhost:3306/my_database
spring.datasource.username=root
spring.datasource.password=ENC(Hu76tW6HJjEp730PNXSFOQ==)
jasypt.encryptor.algorithm=PBEWithMD5AndDES
jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator
jasypt.encryptor.password=foo
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
...>
...
<properties>
...
<jasypt.version>3.0.4</jasypt.version>
</properties>
<dependencies>
...
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>${jasypt.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
....
<plugin>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-maven-plugin</artifactId>
<version>${jasypt.version}</version>
</plugin>
</plugins>
</build>
</project>
The error I get:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.datasource.password' to java.lang.String:
Reason: either 'jasypt.encryptor.password', one of ['jasypt.encryptor.private-key-string', 'jasypt.encryptor.private-key-location'] for asymmetric encryption, or one of ['jasypt.encryptor.gcm-secret-key-string', 'jasypt.encryptor.gcm-secret-key-location', 'jasypt.encryptor.gcm-secret-key-password'] for AES/GCM encryption must be provided for Password-based or Asymmetric encryption
Action:
Update your application's configuration