3

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
user1387365
  • 71
  • 1
  • 3
  • 7
  • Have you set APP_ENCRYPTION_PASSWORD as an environment variable? – Jeshurun May 15 '12 at 12:13
  • I have check my configuration by using YOUR_PLAIN_TEXT_PASSWORD_HERE entry Its working fine.After using command prompt C:\jasypt-1.9.0\bin>set APP_ENCRYPTION_PASSWORD='lKmVnTVL3zSJXrZpwFmhd6crSHLzYihH' still same error is appear. I am strugling from last 2 days please help me out thanks – user1387365 May 17 '12 at 06:49

2 Answers2

6

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" />.

Community
  • 1
  • 1
Jeshurun
  • 22,940
  • 6
  • 79
  • 92
  • I have check my configuration by using YOUR_PLAIN_TEXT_PASSWORD_HERE entry Its working fine.After using command prompt C:\jasypt-1.9.0\bin>set APP_ENCRYPTION_PASSWORD='lKmVnTVL3zSJXrZpwFmhd6crSHLzYihH' still same error is appear. I am strugling from last 2 days please help me out thanks – user1387365 May 17 '12 at 06:46
  • What operating system and version are you on? – Jeshurun May 17 '12 at 07:08
  • hi jeshurun, I have set the environment variable in windows variable Name= APP_ENCRYPTION_PASSWORD Variable Value=lKmVnTVL3zSJXrZpwFmhd6crSHLzYihH change passwordEnvName to passwordSysPropertyName but still i am getting same error, what I will do i dont understand. Is the any entry is required my app servr (JBOSS) – user1387365 May 17 '12 at 11:10
  • If you set it as a windows environment variable then do NOT change passwordEnvName to passwordSysPropertyName. Only make that change if you are passing it as a startup parameter to your app server (using the -D= syntax. – Jeshurun May 17 '12 at 12:12
  • set passwordEnvName after setting windows env variable showing error org.jasypt.exceptions.EncryptionOperationNotPossibleException – user1387365 May 18 '12 at 05:55
  • Try `-DAPP_ENCRYPTION_PASSWORD=testuser` – vegemite4me Mar 31 '15 at 09:36
-1

Once you set the Environment variable. Please restart your eclipse. You may not face this isssue. If issue still persist than try to find your environment variables by below code..

Map<String, String> env = System.getenv();
            for (String envName : env.keySet()) {
                System.out.format("%s=%s%n", envName,
                                  en`enter code here`v.get(envName));
            } 
Robert
  • 5,278
  • 43
  • 65
  • 115