0

I am trying to decrypt password with jasypt, where password is passed as a VM argument. xml file which is using this looks like -

<bean id="strongEncryptor"
          class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
        <property name="config">
            <bean class="org.jasypt.encryption.pbe.config.SimpleStringPBEConfig"
                  p:algorithm="PBEWithMD5AndDES" p:password="#{systemProperties['jasypt.encryptor.password']}"
                  p:providerClassName="org.bouncycastle.jce.provider.BouncyCastleProvider"/>
        </property>
    </bean>

    <bean id="propertyConfigurer" p:ignoreResourceNotFound="true" p:nullValue="{null}"
          class="org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer">
        <constructor-arg ref="strongEncryptor" />
        <property name="locations">
            <list>
                <value>file:#{systemProperties['appconfig.dir']}/farms/local-testing/application.properties</value>
            </list>
        </property>
        <property name="ignoreUnresolvablePlaceholders" value="true"></property>
    </bean>

Here if I don't write <property name="ignoreUnresolvablePlaceholders" value="true"> then I get errors like various properties not defined however those are defined in base\application.properties.

VM arguments are provided as

-Dspring.config.location=appconfig/base/,appconfig/farms/local-testing/ -Dappconfig.dir=/opt/apps/globalpayments/svx/appconfig -Djasypt.encryptor.password=randompassword

Not able to understand whats happening here.

Also one important thing here is if I don't provide VM arguments then it should ignore this and provide encrypted value as string instead of decrypted value.

Any pointers would be helpful.

Thanks in advance.

codeomnitrix
  • 4,179
  • 19
  • 66
  • 102

1 Answers1

0

How about doing like the below. I splited the environment variables config and encryptor, and removed some attributes because I do not understand for what they are. Note that you need to pass the "jasypt_encryptor_password" as "Environmental" variable, not the VM argument.

<bean id="envVarConfig"
  class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor" p:algorithm="PBEWithMD5AndDES" p:password="jasypt_encryptor_password" p:providerClassName="org.bouncycastle.jce.provider.BouncyCastleProvider" />

<bean id="configEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor" p:config-ref="envVarConfig" />

<bean id="propertyConfigurer" class="org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer">
        <constructor-arg ref="configEncryptor" />
        <property name="locations">
            <list>
                <value>file:///${appconfig.dir}/farms/local-testing/application.properties</value>
            </list>
        </property>
</bean>

Hope it works for you.

hwanud
  • 1