Encrypt value in property file

I have a password in the properties file that I want to encrypt using any two-way encryption.

password = 123456

I use it in spring -security xml to authenticate the active directory. This time the password should be decrypted. Can someone tell me how to do this?

I'm new to spring, and I'm not quite sure which path is here. I used Jasypt, but I get LDAP 52 authentication, which means the password is incorrect. I assume that decryption does not work correctly.

I am using spring 4.

+4
source share
2 answers

Take a look here . The main steps:

  • XML spring:

    xmlns:encryption="http://www.jasypt.org/schema/encryption"

  • :

    <encryption:strong-password-encryptor id="passwordEncryptor" />

  • : property-placeholder, :

    <encryption:encryptable-property-placeholder encryptor="passwordEncryptor" location="classpath:application.properties"/>

  • , , Encryptable Property Placeholder , . , () ( ), .

    password=ENC(G6N718UuyPE5bHyWKyuLQSm02auQPUtm)

+3

. . AES/. ( google)

springsecurity.xml AES,

<beans:bean id="Decrypt" class="com.xxx.encoder.Decrypt">
    </beans:bean>

,

<beans:bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <beans:constructor-arg value="${host}" />
        <beans:property name="base" value="" />
        <beans:property name="userDn" value="${userDN}" />
        **<beans:property name="password" value="#{Decrypt.decrypt('${password}')}" />**

, .

0

All Articles