spring 数据库用户名密码加密解密
2016-11-08 11:17
183 查看
参考http://blog.csdn.net/zhangt85/article/details/42122311
<bean id="propertyConfigurer"
class="com.pingan.ecological.util.EncryptPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:*.properties</value>
</list>
</property>
<property name="fileEncoding" value="GBK" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
EncryptPropertyPlaceholderConfigurer.java
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
private static Logger logger = LogManager.getLogger(EncryptPropertyPlaceholderConfigurer.class);
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
throws BeansException {
try {
String passwordKey = "jdbc.password";
String password = props.getProperty(passwordKey);
if (password != null) {
props.setProperty(passwordKey,
DESUtils.getDecryptString(password));
}
super.processProperties(beanFactory, props);
} catch (Exception e) {
logger.error("processProperties", e);
throw new BeanInitializationException(e.getMessage());
}
}
}
<bean id="propertyConfigurer"
class="com.pingan.ecological.util.EncryptPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:*.properties</value>
</list>
</property>
<property name="fileEncoding" value="GBK" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
EncryptPropertyPlaceholderConfigurer.java
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
private static Logger logger = LogManager.getLogger(EncryptPropertyPlaceholderConfigurer.class);
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
throws BeansException {
try {
String passwordKey = "jdbc.password";
String password = props.getProperty(passwordKey);
if (password != null) {
props.setProperty(passwordKey,
DESUtils.getDecryptString(password));
}
super.processProperties(beanFactory, props);
} catch (Exception e) {
logger.error("processProperties", e);
throw new BeanInitializationException(e.getMessage());
}
}
}
相关文章推荐
- spring web项目 数据库用户名密码加密解密
- springMVC web项目 数据库用户名密码加密解密
- springMVC web项目 数据库用户名密码加密解密
- springMVC web项目 数据库用户名密码加密解密
- Spring+mysql+druid对数据库连接的用户名密码加密
- Spring 数据库配置用户名和密码加密
- Phoenix Framework中为数据库用户名和密码加密的方法
- [走火入魔失眠夜]浅谈管理软件信息安全,用户名、密码的加密解密【附C#配套加密解密源码】
- 用户登录时的用户名密码加密解密问题和“记住密码”功能
- 数据库密码加密公用秘要生成器,数据库密码加密解密入口
- [走火入魔失眠夜]浅谈管理软件信息安全,用户名、密码的加密解密【附C#配套加密解密源码】
- 怎样使Spring的applicationContext.xml文件不放入数据库用户名和密码
- 将 Shiro 作为应用的权限基础 五:密码的加密/解密在Spring中的应用
- kettle生成ktr文件_数据库密码的加密与解密
- PB数据库连接描述文件的密码加密和解密原理
- PB数据库连接描述文件的密码加密和解密原理
- [走火入魔失眠夜]浅谈管理软件信息安全,用户名、密码的加密解密【附C#配套加密解密源码】
- Tomcat JNDI 数据库用户名和密码加密(数据库连接池用户和密码加密)
- QuickCSharp框架开发(18)------加密用户名和密码数据与数据库读出的密码进行哈希比较(验证用户是否成功登录)
- [走火入魔失眠夜]浅谈管理软件信息安全,用户名、密码的加密解密【附C#配套加密解密源码】