Encrypting a password within a Spring configuration file

早过忘川 提交于 2019-12-10 23:30:53

问题


I have a Spring bean which uses a username/password as part of its constructor parameters :

<bean id="mysender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
         <property name="c">
             <bean class="org.apache.commons.httpclient.UsernamePasswordCredentials">
                 <constructor-arg value="plaintext"/>
                 <constructor-arg value="plaintext"/>
             </bean>
         </property>
     </bean>

Can I use jasypt to encrypt these parameters from the configuration file only ? The bean "org.apache.commons.httpclient.UsernamePasswordCredentials" will be instantiated with plain text values but to the user they will appear encrypted.

I could use core java library code using this answer : Encrypt Password in Configuration Files? and manually create the bean mysender from within java, then depcript the fields before instantiating org.apache.commons.httpclient.UsernamePasswordCredentials

Or is there a tried method of I have not mentioned which will implement this ?


回答1:


Yes, jasypt can handle this. See

http://www.algowise.com/2013/04/encrypting-passwords-using-jasypt-in.html



来源:https://stackoverflow.com/questions/20149939/encrypting-a-password-within-a-spring-configuration-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!