ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.87k stars 514 forks source link

Error Decrypting: null: EncryptionOperationNotPossibleException #348

Open dbnex14 opened 1 year ago

dbnex14 commented 1 year ago

I am using spring-boot-starter-parent version 2.7.6 and jasypt-spring-boot-starter dependency 3.0.3 (because I could not see 3.0.4 or 3.0.5 due to another issue (https://github.com/ulisesbocchio/jasypt-spring-boot/issues/347). OpenJdk11

Added in pom.xml of my Spring Boot app

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

Added plugin:

<build>
   <plugins>
        ....

    <plugin>
         <groupId>com.github.ulisesbocchio</groupId>
         <artifactId>jasypt-maven-plugin</artifactId>
         <version>3.0.3</version>
    </plugin>
   </plugins>

Annotated my spring boot class

@EnableEncryptableProperties
@SpringBootApplication
public class MyApiApplication {
    public static void main(String[] args) {...}
}

In my application.properties file, I have property myPassword=somePassword

I wrapped it with DEC like: myPassword=DEC(somePassword)

Issuing: mvn jasypt:encrypt -Djasypt.encryptor.password=mysecret

, will successfully encrypt this value and it will become like: myPassword=ENC(7;lajsdfpypaohsd;lahdafay....)

So far, that is all good and it seem to be working as expected.

However, decrypting will fail. After the successfull attempts above, my password is encrypted and looks like: myPassword=ENC(7;lajsdfpypaohsd;lahdafay....)

I would now like to decrypt it to get "somePassword" back so I do following: mvn jasypt:decrypt -Djasypt.encryptor.password=mysecret

[ERROR] Failed to execute goal com.github.ulisesbocchio:jasypt-maven-plugin:3.0.3:decrypt (default-cli) on project myapi: Error Decrypting: null: EncryptionOperationNotPossibleException

And the ENC(....) property in application.properties file is not replaced by DEC(....)

Full output of the command above: mvn jasypt:decrypt -Djasypt.encryptor.password=ackornack [INFO] Scanning for projects... [INFO] [INFO] ----------------------< io.dino.myapi:myapi >---------------------- [INFO] Building myapi 0.0.1-SNAPSHOT [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- jasypt-maven-plugin:3.0.3:decrypt (default-cli) @ myapi --- [INFO] Starting MavenCli v3.6.2 on MyComputer with PID 31152 (C:\Maven\apache-maven-3.6.2\bin..\lib\maven-embedder-3.6.2.jar started by DINO in C:\Dev\intelliJUltimateDev\myapi) [INFO] No active profile set, falling back to default profiles: default [INFO] Post-processing PropertySource instances [INFO] Converting PropertySource configurationProperties [org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource] to AOP Proxy [INFO] Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper [INFO] Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper [INFO] Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper [INFO] Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter [INFO] Started MavenCli in 1.216 seconds (JVM running for 3.797) [INFO] Active Profiles: Default [INFO] Decrypting file src\main\resources\application.properties [INFO] String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing Default String Encryptor [INFO] Encryptor config not found for property jasypt.encryptor.algorithm, using default value: PBEWITHHMACSHA512ANDAES_256 [INFO] Encryptor config not found for property jasypt.encryptor.key-obtention-iterations, using default value: 1000 [INFO] Encryptor config not found for property jasypt.encryptor.pool-size, using default value: 1 [INFO] Encryptor config not found for property jasypt.encryptor.provider-name, using default value: null [INFO] Encryptor config not found for property jasypt.encryptor.provider-class-name, using default value: null [INFO] Encryptor config not found for property jasypt.encryptor.salt-generator-classname, using default value: org.jasypt.salt.RandomSaltGenerator [INFO] Encryptor config not found for property jasypt.encryptor.iv-generator-classname, using default value: org.jasypt.iv.RandomIvGenerator [INFO] Encryptor config not found for property jasypt.encryptor.string-output-type, using default value: base64 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.821 s [INFO] Finished at: 2023-01-29T16:02:11-08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.github.ulisesbocchio:jasypt-maven-plugin:3.0.3:decrypt (default-cli) on project myapi: Error Decrypting: null: EncryptionOperationNotPossibleException -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException