簡體   English   中英

加密屬性文件中的值

[英]encrypt value in properties file

我在屬性文件中有一個密碼,我想用任何雙向加密加密。

password = 123456

我在spring-security xml中使用它進行活動目錄身份驗證。 那個時候密碼應該被解密。 有人能指點我怎么做嗎?

我是春天的新手,我不確定在這里采取什么路線。 我使用了Jasypt但是我得到了LDAP authenticaton錯誤52,這意味着密碼不正確。 我假設解密沒有正確發生。

我正在使用春天4。

看看這里 主要步驟是:

  1. 在spring上下文xml文件中定義名稱空間:

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

  2. 定義加密器:

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

  3. 而不是你的上下文:property-placeholder標簽,使用:

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

  4. 現在,您可以使用加密的屬性,如下所示,加密屬性占位符將確保它們被解密。 請注意,您需要使用與使用定義的編碼器相同的alghorithm(和相同的配置)來加密屬性(密碼)。

    password=ENC(G6N718UuyPE5bHyWKyuLQSm02auQPUtm)

答案我的問題。 幾天后我無法與Jasypt合作。 所以我寫了一個簡單的AES加密/解密。(谷歌上的一些例子)

接下來在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}')}" />**

通過我的屬性文件中的加密密碼,它工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM