Password Management:Password in Configuration File(密码在配置文件中)解决方案
来源:互联网 发布:新手怎么做淘宝分销 编辑:程序博客网 时间:2024/06/13 22:57
注:框架是Struts2+Spring+ibatis
漏洞代码
jdbc.url=jdbc:db2://172.17.33.118:50000/qjxt
jdbc.driverClassName=com.ibm.db2.jcc.DB2Driver
jdbc.username=db2admin
jdbc.password=db2admin
漏洞说明
在配置文件中存储明文密码。
解决方案
密码模糊化,并把模糊化资源分散到系统各处。
采用加密算法AES级别以上。
自定义密码机制。
将jdbc.password的值使用AES算法加密
public class SecurityUtil {
/**
* 加密算法名称AES
*/
private static final String ENCRYPTION_ALGORITHM_NAME = "AES";
/**
* 字符编码
*/
private static final String CHARACTER_ENCODING = "UTF-8";
public static void main(String[] args) {
String str = "admin";
System.out.println("明文:" + str);
// 生成密钥
String keyStr = "jsepc01!";
System.out.println("密钥:" + keyStr);
SecretKey key = SecurityUtil.getKey(keyStr);
// 加密
String miwen = SecurityUtil.encryption(str, key);
System.out.println("密文:" + miwen);
// 解密
String returnStr = SecurityUtil.decryption("3k5KAxN2D7k9QvYUu80kIA==", key);
System.out.println("解密后:" + returnStr);
}
private static SecretKeySpec getKey(String key){
try {
byte[] arrTemp = key.getBytes(CHARACTER_ENCODING);
byte[] arr = new byte[16];
for (int i = 0; i < arrTemp.length; i++) {
arr[i] = arrTemp[i];
}
SecretKeySpec keySpec = new SecretKeySpec(arr, ENCRYPTION_ALGORITHM_NAME);
return keySpec;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
/**
* 加密
*
* @param str
* 明文
* @param key
* 秘钥
* @return 密文
*/
private static String encryption(String str, SecretKey key) {
try {
// 创建密码器
Cipher cp = Cipher.getInstance(ENCRYPTION_ALGORITHM_NAME);
// 设置加密模式
cp.init(Cipher.ENCRYPT_MODE, key);
byte[] strs = str.getBytes(CHARACTER_ENCODING);
// 加密
byte[] cipherStrs = cp.doFinal(strs);
String cipherStr = new BASE64Encoder().encode(cipherStrs);
return cipherStr;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
1.用密文替换原有的明文(properties文件中jdbc.password的value值)
2.创建MyPropertiesPersist类,给password解密,如图
3.在applicationcontext中配置信息 具体如下
<!-- 引入配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/jdbc.properties</value>
</list>
</property>
<property name="propertiesPersister">
<bean class="coml.MyPropertiesPersist"></bean>
</property>
<property name ="ignoreResourceNotFound" value="true"/>
</bean>
- Password Management:Password in Configuration File(密码在配置文件中)解决方案
- Password management in Django 密码管理,记忆线索
- Password File Authentication & Listener Configuration
- Oracle中password file
- Password file
- oracle密码文件认证(password file authentication)
- Password Management Procedures
- GoogleCode中git push密码错误提示解决方案(Invalid username/password)
- password
- password
- Password
- password
- Password
- PASSWORD
- Password
- Password
- Change expired password in AD with C# (使用c# 更改AD 中过期密码)
- fortify——password Management
- 217. Contains Duplicate
- 71. Simplify Path
- java中的排序!
- ubuntu16.04+cuda8.0+opencv3.1+GTX1080配置caffe
- CSS盒子模型
- Password Management:Password in Configuration File(密码在配置文件中)解决方案
- pointer_5
- Android TextView 高亮超链接关键字
- 今日头条 CEO 张一鸣:面试了 2000 个年轻人,混得好的都有这 5 种特质
- arraylist
- jquery中click点击事件嵌套后多次触发的解决方案
- LRU算法的实现
- navicat工具来将SQL Server数据迁移到MySQL
- 裸奔的驴算法刷题日记5-31