Commit 94572fe8 authored by 张俊's avatar 张俊

数据库信息加密处理

parent 2ea9ff57
......@@ -506,6 +506,14 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jasypt/jasypt-spring4 -->
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt-spring4</artifactId>
<version>1.9.3</version>
</dependency>
</dependencies>
<dependencyManagement>
......
package com.changda.gjjapp.encryptor;
import com.changda.cd4j.foundation.core.dto.ResultDto;
import com.changda.gjjapp.zhfwpt.service.qdyxzb.ZhfwptTest;
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.properties.PropertyValueEncryptionUtils;
import org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer;
import org.jasypt.util.text.BasicTextEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller()
@RequestMapping(value = "/encrypt")
public class EncryptController {
@Autowired
private StringEncryptor stringEncryptor;
@ResponseBody
@RequestMapping("/jasyptEnc")
public ResultDto encrypt(String encStr) {
ResultDto resultDto = new ResultDto();
resultDto.setData(stringEncryptor.encrypt(encStr));
resultDto.setSuccess(true);
return resultDto;
}
@ResponseBody
@RequestMapping("/jasyptDec")
public ResultDto decrypt(String decStr) {
ResultDto resultDto = new ResultDto();
resultDto.setData(stringEncryptor.decrypt(decStr));
resultDto.setSuccess(true);
return resultDto;
}
}
package com.changda.gjjapp.encryptor;
import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
@Configuration
public class EncryptorConfig {
/*@Bean
public StandardPBEStringEncryptor standardPBEStringEncryptor() {
EnvironmentStringPBEConfig stringPBEConfig = new EnvironmentStringPBEConfig();
stringPBEConfig.setAlgorithm("PBEWithMD5AndDES");
stringPBEConfig.setPassword("root");
StandardPBEStringEncryptor pbeStringEncryptor = new StandardPBEStringEncryptor();
pbeStringEncryptor.setConfig(stringPBEConfig);
return pbeStringEncryptor;
}*/
@Bean
public EncryptablePropertyPlaceholderConfigurer propertyConfigurer(StringEncryptor pbeStringEncryptor) {
EncryptablePropertyPlaceholderConfigurer placeholderConfigurer = new EncryptablePropertyPlaceholderConfigurer(pbeStringEncryptor);
DefaultResourceLoader defaultResourceLoader = new DefaultResourceLoader();
placeholderConfigurer.setLocations(defaultResourceLoader.getResource("classpath:gjj.properties"));
return placeholderConfigurer;
}
@Bean
public StringEncryptor stringEncryptor() {
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
// 加密盐值
config.setPassword("gjjcdgs856177110");
// 加密算法
config.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM);
// key迭代次数
config.setKeyObtentionIterations("1000");
// 池大小
config.setPoolSize("1");
config.setProviderName("SunJCE");
// 随机盐生成器
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
// 加密后输出字符串编码方式
config.setStringOutputType("base64");
encryptor.setConfig(config);
return encryptor;
}
}
......@@ -15,16 +15,15 @@ FileTemplatPath=D:\\JavaFileDir
jdbc.type=oracle
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@192.168.101.194:1521:zfgjj
jdbc.username=ZHFW80
jdbc.password=ZHFW80
jdbc.url=ENC(O/MRgz1LcC4g+4JLVPeEEQYSJQ8MNNvUJ6ri4Izl5IdK1NEkMhRvmi+54sNI/HmoOOxZpcZY/64vTaXZvKBNQg==)
jdbc.username=ENC(v/urlgt6tqaEsE717EpUf0dTSg4VVPru)
jdbc.password=ENC(v/urlgt6tqaEsE717EpUf0dTSg4VVPru)
jdbc.type.ss=oracle
jdbc.driver.ss=oracle.jdbc.driver.OracleDriver
jdbc.url.ss=jdbc:oracle:thin:@192.168.101.194:1521:zfgjj
jdbc.username.ss=ZHFW80
jdbc.password.ss=ZHFW80
jdbc.url.ss=ENC(O/MRgz1LcC4g+4JLVPeEEQYSJQ8MNNvUJ6ri4Izl5IdK1NEkMhRvmi+54sNI/HmoOOxZpcZY/64vTaXZvKBNQg==)
jdbc.username.ss=ENC(v/urlgt6tqaEsE717EpUf0dTSg4VVPru)
jdbc.password.ss=ENC(v/urlgt6tqaEsE717EpUf0dTSg4VVPru)
#jdbc.type=oracle
#jdbc.driver=oracle.jdbc.driver.OracleDriver
......
......@@ -27,15 +27,12 @@
<aop:aspectj-autoproxy proxy-target-class="true">
</aop:aspectj-autoproxy>
<!-- 加载配置属性文件 -->
<context:property-placeholder
ignore-unresolvable="true" location="classpath:gjj.properties" />
<context:property-placeholder
ignore-unresolvable="true" location="classpath:gjj_bussiness.property" />
<!--<context:property-placeholder ignore-unresolvable="true" location="classpath:gjj.properties" />-->
<context:property-placeholder ignore-unresolvable="true" location="classpath:gjj_bussiness.property" />
<!-- 加载应用属性实例,可通过 @Value("#{APP_PROP['jdbc.driver']}") String jdbcDriver
方式引用 -->
<util:properties id="APP_PROP" location="classpath:gjj.properties"
local-override="true" />
<util:properties id="APP_PROP" location="classpath:gjj.properties" local-override="true" />
<!-- 使用Annotation自动注册Bean,解决事物失效问题:在主容器中不扫描@Controller注解,在SpringMvc中只扫描@Controller注解。 -->
<context:component-scan base-package="com.changda"><!-- base-package
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment