生成加密串
public class Encryptor {
public static void main(String[] args) {
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword("mysalt");//自定义加密盐
String myEncryptedPassword = textEncryptor.encrypt("jdbcpasword");
System.out.println("Encrypted DB password: " + myEncryptedPassword );
}
}
jdbc连接数据库密码设置为加密的使用ENC()
password: ENC(myEncryptedPassword )
一、.springMvc
1.引入包
<dependency><groupId>org.jasypt</groupId><artifactId>jasypt-spring4</artifactId><version>1.9.3</version> </dependency>
2.applicationContext.xml添加配置
<!--jasypt的核心配置--><bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:jdbc.properties</value></list></property><property name="ignoreResourceNotFound" value="true"/><property name="ignoreUnresolvablePlaceholders" value="true"/> </bean> <bean id="stringEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor"><property name="algorithm" value="PBEWithMD5AndDES"/><property name="password" value="mysalt"/>//自定义加密盐 </bean>
二、springboot
1.引入包 <dependency><groupId>com.github.ulisesbocchio</groupId><artifactId>jasypt-spring-boot-starter</artifactId><version>2.1.2</version> </dependency>
2.启动命令增加
-Djasypt.encryptor.password=mysalt//自定义加密盐