Cannot decrypt the password in application.yml properly if war file in the tomcat/webapps

22 Views Asked by At

Spring boot version:3.2.3

Tomcat version:

Using CATALINA_BASE:   "C:\Users\zhibo\Desktop\Apache\Tomcat\apache-tomcat-10.1.19"
Using CATALINA_HOME:   "C:\Users\zhibo\Desktop\Apache\Tomcat\apache-tomcat-10.1.19"
Using CATALINA_TMPDIR: "C:\Users\zhibo\Desktop\Apache\Tomcat\apache-tomcat-10.1.19\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk-21.0.2"
Using CLASSPATH:       "C:\Users\zhibo\Desktop\Apache\Tomcat\apache-tomcat-10.1.19\bin\bootstrap.jar;C:\Users\zhibo\Desktop\Apache\Tomcat\apache-tomcat-10.1.

Jasypt version:

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

Here is the issue, in IDEA I can encrypt/decrpyt the database password properly which in the application.yml file. However when I generate the war file and put it in tomcat and try to start up the program I got following exception:

Reason: java.security.NoSuchAlgorithmException: PBEWithMD5AndTripleDES  SecretKeyFactory not available

And I setup the values in the catalina.properties file with following properties:

jasypt.encryptor.password=password 
jasypt.encryptor.algorithm=PBEWithMD5AndTripleDES 
jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator

What should I do to fix this ?

1

There are 1 best solutions below

0
Vincent Zheng On

I fix the issue... The way I encryprt my password was using StandardPBEStringEncryptor, and that is why I cannot choose the proper algorithm for that. Once I choose the PooledPBEStringEncryptor and following the example on the github to do the config, encrypt works. And I put all the jasypt config except password part into application.yml and the jasypt.encryptor.password was set in the catalina.properties` for the tomcat, everything solved now