1. 程式人生 > >druid資料庫賬號密碼加密解密

druid資料庫賬號密碼加密解密

1.加密

cmd    java -cp D://druid-1.0.13.jar com.alibaba.druid.filter.config.ConfigTools 賬號
cmd    java -cp D://druid-1.0.13.jar com.alibaba.druid.filter.config.ConfigTools 密碼

2.解密

import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.pool.DruidDataSource;

public class DecryptDruidSource extends DruidDataSource {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void setUsername(String username) {
		try {
			username = ConfigTools.decrypt(username);
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.setUsername(username);
	}
	
	@Override
	public void setPassword(String password) {
		try {
			password = ConfigTools.decrypt(password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.setPassword(password);
	}
}

3.資料庫配置檔案

jdbc.username=bDxg0e3HnAhCfgmf5/Jn6FNsb63yH7O/xVJrKteDcjc99RWiF27aLklo6h0U8lDU4WzPJfwu35JlUWTtXRfOdw==(cmd中生成的字串)


jdbc.password=NdbQY4EBWtGre6VMBQglqrEdoYlh2gYHTfGb8Cv3Y8/l313JMGgbTuRJHCSm+9FLgHhot/1CH2PTzzCDXsRcWQ==(cmd中生成的字串)


4.spring配置檔案

<bean id="*" class="更改為第2步所定義的類">

列如:

<bean id="druid" class="com.spark.druid.DecryptDruidSource">