欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring4 Jasypt1.9.2 Integration 博客分类: 數據安全 Security 

程序员文章站 2024-03-13 18:53:57
...

1.add jasypt with maven

       <!-- Encryption / Decryption -->

        <dependency>

            <groupId>org.jasypt</groupId>

            <artifactId>jasypt-spring3</artifactId>

            <version>${jasypt.version}</version>

 

       </dependency>

2.Download jasypt to encrypt passwod on tomcat server

   1)execute command under folder bin to list available algorithms

      ./listAlgorithms.sh

   2)select a algorithm listed above to encrypt database password

     ./encrypt.sh input=dbpasword algorithm=PBEWITHSHA1ANDRC2_40 password=jasypt_is_cool

 

  note:----ERROR-----------------------

 

          Operation not possible (Bad input or parameters)

 

           Please select another algorithm  

   

3.add properties file:spring.properties

 

   jdbc.driverClassName=oracle.jdbc.driver.OracleDriver

   jdbc.url=jdbc:oracle:thin:@192.168.88.230:1521:xe

   jdbc.username=cms

 

   jdbc.password=ENC(xBpvib/4aRiUz0nH5besvA==)

 

4.add the following information in spring configuration file

 

  <bean id="jasyptConfiguration"

      class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig"

      p:algorithm="PBEWITHSHA1ANDRC2_40"

      p:passwordEnvName="JASYPT"/>

 

<bean id="propertyPasswordEncryptor"

      class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor"

      p:config-ref="jasyptConfiguration"/>

      

<bean class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">

   <constructor-arg>

      <ref bean="propertyPasswordEncryptor"/>

    </constructor-arg>

    <property name="location" value="classpath:spring.properties"/> 

    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>

</bean>

 

 

5. Set environment variable in /etc/init.d/tomcat8 file

    JASYPT="dbpassword"

    export JASYPT

6. Restart tomcat

 

相关标签: Security