Unable to decrypt an encrypted password using Jasypt with Spring 2.5.6

713 Views Asked by At

I have not been able to make Jasypt work with Spring 2.5.6 to decrypt an encrypted password from the properties file. I do not see any error in the logs either.

I found one example of someone using Jasypt with Spring 2.5.6. When I try running this program, I am getting Exception in thread "main" org.jasypt.exceptions.EncryptionOperationNotPossibleException.

If anyone has been able to successfully use Jasypt with Spring 2.5.6, please post the code.

pom.xml:

    <!-- Spring framework -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6</version>
</dependency>

  <dependency>
      <groupId>org.jasypt</groupId>
      <artifactId>jasypt-spring2</artifactId>
      <version>1.9.2</version>
  </dependency>

Spring-datasource.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:encryption="http://www.jasypt.org/schema/encryption"
   xmlns:p="http://www.springframework.org/schema/p"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean id="environmentVariablesConfiguration"
      class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
    <property name="algorithm" value="PBEWithMD5AndDES" />
    <property name="password" value="APP_ENCRYPTION_PASSWORD" />
</bean>

<bean id="configurationEncryptor"
      class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
    <property name="config" ref="environmentVariablesConfiguration" />
</bean>

<bean id="propertyConfigurer"
      class="org.jasypt.spring2.properties.EncryptablePropertyPlaceholderConfigurer">
    <constructor-arg ref="configurationEncryptor" />
    <property name="locations">
        <list>
            <value>classpath:properties/application.properties</value>
        </list>
    </property>

</bean>

<bean id="myClass" class="com.springjasypt.customer.MyClass">
    <property name="username" value="${my.class.username}" />
    <property name="password" value="${my.class.password}" />
</bean>

application.properties

my.class.password=ENC(piW7egF06tLgj3Dkji5U+sEmmdMjPMvA)
my.class.username=superman

Command used to encrypt password:

java -cp C:\reci\apps\tools\mavenpro\org\jasypt\jasypt\1.9.2\jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI password=APP_ENCRYPTION_PASSWORD algorithm=PBEWITHMD5ANDDES input=secretpassword*123*
0

There are 0 best solutions below