我正在尝试使用jasypt解密密码,其中密码是作为VM参数传递的。使用它的xml文件看起来像-
<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>在这里,如果我没有编写<property name="ignoreUnresolvablePlaceholders" value="true">,那么我会得到一些错误,比如没有定义各种属性,但是这些属性是在base\application.properties中定义的。
VM参数以如下形式提供
-Dspring.config.location=appconfig/base/,appconfig/farms/local-testing/ -Dappconfig.dir=/opt/apps/globalpayments/svx/appconfig -Djasypt.encryptor.password=randompassword
不能理解这里发生了什么。
同样重要的是,如果我不提供VM参数,那么它应该忽略这一点,并以字符串而不是解密值的形式提供加密值。
任何提示都会很有帮助。
提前谢谢。
发布于 2018-06-01 09:45:21
不如像下面这样做。我拆分了环境变量config和encryptor,并删除了一些属性,因为我不了解它们是什么。请注意,您需要将"jasypt_encryptor_password“作为”环境“变量传递,而不是VM参数。
<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>希望它能为你工作。
https://stackoverflow.com/questions/49736666
复制相似问题