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