Getting error org.jasypt.exceptions.EncryptionInitializationException: Password not set for Password Based Encryptor

user1387365 picture user1387365 · May 15, 2012 · Viewed 11.8k times · Source

I am using jasypt-1.9.0 for encryption.

Jdbc.properties

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@localhost:1521:ORCL
jdbc.username=testuser
jdbc.password=ENC(lKmVnTVL3zSJXrZpwFmhd6crSHLzYihH)
hibernate.dialect=org.hibernate.dialect.OracleDialect
jpa.databasePlatform=toplink.hibernate.EssentialsHSQLPlatformWithNative
jpa.database=ORCL
C:\jasypt-1.9.0\bin>encrypt input=testuser password=testuser

----ENVIRONMENT-----------------
Runtime: Sun Microsystems Inc. Java HotSpot(TM) Client VM 1.5.0_17-b04
----ARGUMENTS-------------------
input: testuser
password: testuser
----OUTPUT----------------------

lKmVnTVL3zSJXrZpwFmhd6crSHLzYihH

I got the reference from one of your site. I am using multiple context file. I have configured

<bean
class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfi
gurer">
<constructor-arg>
<bean class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
<property name="config">
<bean
class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
<property name="algorithm" value="PBEWithMD5AndDES" />
<property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" />
</bean>
</property>
</bean>
</constructor-arg>
<property name="locations">
<list>
<value>classpath:/META-INF/props/db/jdbc.properties</
value>
</list>
</property>
</bean>

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"
value="${jdbc.driverClassName}" ></property>

<property name="url"
value="${jdbc.url}" ></property>
<property name="username"
value="${jdbc.username}" ></property>
<property name="password"
value="${jdbc.password}"></property>
<property name="initialSize" value="10"> </property>
<property name="maxActive"
value="30"> </property>
<property name="maxIdle"
value="10"> </property>
<property name="maxWait"
value="5000"> </
property>
<property name="removeAbandoned"
value="true"> </
property>
<property name="logAbandoned"
value="true"> </
property>

</bean>

When I login my application I am getting error::

org.jasypt.exceptions.EncryptionInitializationException: Password not set for Password Based Encryptor

Answer

Jeshurun picture Jeshurun · May 15, 2012

It appears your "APP_ENCRYPTION_PASSWORD" property is not properly set as an environment variable. See this link to check if it has been properly set as an environment variable. To check if there is a problem with the rest of your configuration, change <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" /> to <property name="password" value="YOUR_PLAIN_TEXT_PASSWORD_HERE" /> and replace YOUR_PLAIN_TEXT_PASSWORD_HERE with your plain text password to test if the rest of your configuration is working.

To set APP_ENCRYPTION_PASSWORD as an environment variable in Windows XP see this link.

Alternatively, you can pass the password in as a vm argument when you run your program. If it is a standalone program, you will pass it like java ClassWithMain -DAPP_ENCRYPTION_PASSWORD=your_password. If it is a web application, you will have to pass the same arguments when starting your server. See this question on SO on how to do that for tomcat. Then in your spring configuration, replace <property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" /> with <property name="passwordSysPropertyName" value="APP_ENCRYPTION_PASSWORD" />.