采用DES加密方式对properties配置文件敏感信息加密处理

本文介绍了一种在项目中为保护数据库用户名和密码等敏感信息,采用DES加密方法对properties配置文件进行加密处理的方法。涉及到的关键类包括MyWebConstant、EncryptablePropertyPlaceholderConfigurer和DesEncrypt,以及在applicationContext.xml中的配置。
摘要由CSDN通过智能技术生成

由于项目的需要,要求对配置文件中的敏感信息进行加密处理,例如数据库用户名密码之类的


处理方式如下:


MyWebConstant

/**
 * 对外接口,管理公共常量
 * 对应properties中的key值
 * @author Administrator
 *
 */
public class MyWebConstant {

    public static final String JDBC_DATASOURCE_DRIVERCLASSNAME_KEY = "jdbc.driverClassName";
    
    public static final String JDBC_DATASOURCE_URL_KEY = "jdbc.url";
    
    public static final String JDBC_DATASOURCE_USERNAME_KEY = "jdbc.username";
    
    public static final String JDBC_DATASOURCE_PASSWORD_KEY = "jdbc.password";
}


EncryptablePropertyPlaceholderConfigurer.java



import java.util.Properties;

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;

/**
 * 配置文件解密核心类
 * 作为自定义类加到配置文件中,解密使用
 * @author Administrator
 *
 */
public class EncryptablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

	protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
			throws BeansException {
		try {
			// DesEncrypt des = new DesEncrypt();
			String username = props.getProperty(MyWebConstant.JDBC_DATASOURCE_USERNAME_KEY);
			if (username != null) {
				props.setProperty(MyWebConstant.JDBC_DATASOURCE_USERNAME_KEY,
						DesEncrypt
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值