#加密前
#datasource.type=mysql
#datasource.driverClassName=com.mysql.jdbc.Driver
#datasource.url=jdbc:mysql://localhost:3306/yjj?useUnicode=true&characterEncoding=utf8 #datasource.username=root #datasource.password=root #加密后
datasource.type=2DF0ADA00FAA99D2
datasource.driverClassName=DFB084E48D901F55B4765B6B6DEEEA685621CEAB85E65590
datasource.url=CD1E7D3A7DEED845CC284EB8AB50F88E171BEAD6E699A4B2E87A3F36434640EA07523DB201ACF884EF00CBBAD67FB52A04960D6C3E91E3EABF370CE3E6FACD06915D92108869CBB9 datasource.username=63AEB7FA5F01BC70 datasource.password=63AEB7FA5F01BC70
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;
import cn.com.dbappsecurity.common.utils.DesEncrypt; import cn.com.dbappsecurity.common.utils.MyWebConstant;
public class EncryptablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer { private static final String key = MyWebConstant.JDBC_DESC_KEY;
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.Decrypt(username, DesEncrypt.hex2byte(key))); }
String password =
props.getProperty(MyWebConstant.JDBC_DATASOURCE_PASSWORD_KEY); if (password != null) {
props.setProperty(MyWebConstant.JDBC_DATASOURCE_PASSWORD_KEY, DesEncrypt.Decrypt(password, DesEncrypt.hex2byte(key))); }
String url = props.getProperty(MyWebConstant.JDBC_DATASOURCE_URL_KEY); if (url != null) {
props.setProperty(MyWebConstant.JDBC_DATASOURCE_URL_KEY, DesEncrypt.Decrypt(url, DesEncrypt.hex2byte(key))); }
String driverClassName =
props.getProperty(MyWebConstant.JDBC_DATASOURCE_DRIVERCLASSNAME_KEY); if(driverClassName != null){
props.setProperty(MyWebConstant.JDBC_DATASOURCE_DRIVERCLASSNAME_KEY, DesEncrypt.Decrypt(driverClassName, DesEncrypt.hex2byte(key))); }
String dbtype = props.getProperty(MyWebConstant.JDBC_DATASOURCE_TYPE_KEY); if(dbtype != null){
props.setProperty(MyWebConstant.JDBC_DATASOURCE_TYPE_KEY, DesEncrypt.Decrypt(dbtype, DesEncrypt.hex2byte(key))); }
super.processProperties(beanFactory, props); } catch (Exception e) { e.printStackTrace();
throw new BeanInitializationException(e.getMessage()); } } }
/******************************JDBC相关BEGIN***************************************/ public static final String JDBC_DESC_KEY = \"0001000200030004\";
/**数据库类型**/
public static final String JDBC_DATASOURCE_TYPE_KEY = \"datasource.type\";
public static final String JDBC_DATASOURCE_DRIVERCLASSNAME_KEY = \"datasource.driverClassName\";
public static final String JDBC_DATASOURCE_URL_KEY = \"datasource.url\";
public static final String JDBC_DATASOURCE_USERNAME_KEY = \"datasource.username\";
public static final String JDBC_DATASOURCE_PASSWORD_KEY = \"datasource.password\";
/******************************JDBC相关END***************************************/
因篇幅问题不能全部显示,请点此查看更多更全内容