How database-related information is encrypted in a property file in a spring configuration

Source: Internet
Author: User
how database-related information is encrypted in a property file in a spring configuration

Project, we generally have some configuration information encryption into the properties file, or other places, such as the database password or URL, user name can be encrypted into the properties file, after the program starts, there will be a corresponding decryption mechanism, restore information, to connect the database and so on.

In the spring framework, the class that reads the property configuration is Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.

Therefore, the general information decryption function is to extend this class implementation. However, now the Jasypt Library also helps us to implement such a function (http://www.jasypt.org/), you can see the document, how to configure the project.


In this example, Org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer is the encryption mechanism implemented by the extended Spring attribute configuration class.

Configuration examples:

<span style= "FONT-SIZE:18PX;" ><bean id= "Environmentvariablesconfiguration" class= " Org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig "> <property name=" algorithm "value=" pbewithmd5a Nddes "/> <property name=" password "value=" root "/> </bean> <bean id=" Configurationencry Ptor "class=" Org.jasypt.encryption.pbe.StandardPBEStringEncryptor "> <property name=" config "ref=" Environment Variablesconfiguration "/> </bean> <bean id=" Propertyconfigurer "class=" org.jasypt.spring31.properties . Encryptablepropertyplaceholderconfigurer "> <constructor-arg ref=" configurationencryptor "/> <p Roperty name= "Locations" > <list> <value>classpath:/jasyptprop/jasypt.properties </value> </list> </property> <property name= "fileencoding" value= "Utf-8" /> </bean></span>
Among them, cryptographic parameters such as algorithms, we can configure themselves.


For detailed test code see: Https://github.com/sdcuike/springmvc-ajax/blob/master/springMvc/src/test/java/com/doctor/Jasypt/JasyptTest.java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.