我做了一个系统,做完了,我们经理要我把数据库里面的dbconfig.properties文件加密,#Database Settings
#db url
DATABASE_URL=10.1.3.220
#222.73.31.69
#db name
DATABASE_NAME=rwcm
#db login user name
USERNAME=A8E4667ADA143D75B331E012FB568718
#db login user password
PASSWORD=987A6A3F7EB623CA04B113B7177952EC
#db port
DATABASE_PORT=1521
driverClassName=oracle.jdbc.driver.OracleDriver
上面的是配置访问数据库的帐号密码,我写的密文,我另外写了一个解密类,但是我解密了里面然后返回出来
public class MyConfigurer extends PropertyPlaceholderConfigurer{ public MyConfigurer(){
processProperties();
//PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE
}
protected void processProperties()
throws BeansException {
Properties pro = new Properties();
try {
InputStream in;
in= MyConfigurer.class.getResourceAsStream("/dbconfig.properties");
pro.load(in);;
in.close();
String un = pro.getProperty("USERNAME");
String ps=pro.getProperty("PASSWORD");
if(un!=null){
System.out.println(AESUtil.decrypt(ps,"r20100716w"));
pro.setProperty("USERNAME", AESUtil.decrypt(un,"r20100716w"));
System.out.println("---已经初始化用户名");
pro.setProperty("PASSWORD", AESUtil.decrypt(ps,"r20100716w"));
System.out.println("---已经初始化密码");
FileOutputStream fos=new FileOutputStream("/dbconfig.properties");
pro.store(fos,"");
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
我继承了spring的PropertyPlaceholderConfigurer这个类,为什么我启动tomcat去访问数据库提示帐号活密码错误,登录拒绝,所以想问问大家怎么替换那些密文?我需要别人看那个properties文件的时候里面是密文,但是需要操作数据库的时候拿的是解密了的密码和帐号,这个怎么搞?求告诉解决
#db url
DATABASE_URL=10.1.3.220
#222.73.31.69
#db name
DATABASE_NAME=rwcm
#db login user name
USERNAME=A8E4667ADA143D75B331E012FB568718
#db login user password
PASSWORD=987A6A3F7EB623CA04B113B7177952EC
#db port
DATABASE_PORT=1521
driverClassName=oracle.jdbc.driver.OracleDriver
上面的是配置访问数据库的帐号密码,我写的密文,我另外写了一个解密类,但是我解密了里面然后返回出来
public class MyConfigurer extends PropertyPlaceholderConfigurer{ public MyConfigurer(){
processProperties();
//PropertyPlaceholderConfigurer.SYSTEM_PROPERTIES_MODE_OVERRIDE
}
protected void processProperties()
throws BeansException {
Properties pro = new Properties();
try {
InputStream in;
in= MyConfigurer.class.getResourceAsStream("/dbconfig.properties");
pro.load(in);;
in.close();
String un = pro.getProperty("USERNAME");
String ps=pro.getProperty("PASSWORD");
if(un!=null){
System.out.println(AESUtil.decrypt(ps,"r20100716w"));
pro.setProperty("USERNAME", AESUtil.decrypt(un,"r20100716w"));
System.out.println("---已经初始化用户名");
pro.setProperty("PASSWORD", AESUtil.decrypt(ps,"r20100716w"));
System.out.println("---已经初始化密码");
FileOutputStream fos=new FileOutputStream("/dbconfig.properties");
pro.store(fos,"");
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
我继承了spring的PropertyPlaceholderConfigurer这个类,为什么我启动tomcat去访问数据库提示帐号活密码错误,登录拒绝,所以想问问大家怎么替换那些密文?我需要别人看那个properties文件的时候里面是密文,但是需要操作数据库的时候拿的是解密了的密码和帐号,这个怎么搞?求告诉解决
解决方案 »
- 如何实现删除多条信息
- [求助] Tomcat/Resin 如何与 Windows 系统账户集成?
- spring+hibernate的问题...
- 主要从事eHR项目开发和维护
- HttpClient实现post请求并加入NTLM认证
- 在STRUTS中怎么实现这个功能!
- 100分看看我下面的socket代码
- java应用程序和java小应用程序的区别,大哥大姐分不多了,全在这了,谢谢
- 求教一个关于查询连续7天数据的sql问题
- 不在方法签名中加入throw Exception, 那么方法还能抛出异常吗
- struts2自定义拦截器实现Interceptor接口问题
- C++中能否实现像java中的二维数组
这里取数据把in的数据改掉就可以了~
class="com.bean.DecryptPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:system.properties</value>
</list>
public class DecryptPropertyPlaceholderConfigurer
extends PropertyPlaceholderConfigurer {
private Resource[] locations; ① 重新定义父类中的这个同名属性
private Resource keyLocation; ② 用于指定密钥文件
public void setKeyLocation(Resource keyLocation) {
this.keyLocation = keyLocation;
}
public void setLocations(Resource[] locations) {
this.locations = locations;
}
public void loadProperties(Properties props) throws IOException {
if (this.locations != null) {
PropertiesPersister propertiesPersister = new DefaultPropertiesPersister();
for (int i = 0; i < this.locations.length; i++) {
Resource location = this.locations[i];
if (logger.isInfoEnabled()) {
logger.info("Loading properties file from " + location);
}
InputStream is = null;
try {
is = location.getInputStream();
③ 加载密钥
Key key = DESEncryptUtil.getKey(keyLocation.getInputStream());
④ 对属性文件进行解密
is = DESEncryptUtil.doDecrypt(key, is);
⑤ 将解密后的属性流装载到props中
if(fileEncoding != null){
propertiesPersister.load(props,
new InputStreamReader(is,fileEncoding));
}else{
propertiesPersister.load(props ,is);
}
} finally {
if (is != null)
is.close();
}
}
}
}
}
}