Springboot 本项目用于配置文件jasypt加密
加密的目的是为了安全,否则你会得到你的配置文件,你不会加密,你会得到你数据库的账户密码.
添加到配置文件中: #加密的盐 jasypt.encryptor.password:yan
建立main对您的数据库进行测试,redis账号密码进行加密
@Test public void jasyptTest(){
BasicTextEncryptor encryptor = new BasicTextEncryptor(); ///在配置文件中加密盐 encryptor.setPassword("yan"); //账号 System.out.println(encryptor.encrypt("root")); //密码 System.out.println(encryptor.encrypt("root")); }
打印出来的是: SMZ qN 4u965ME2dwarUSg== QHRGcpI4YUtB6a6VQCpIFg== 使用配置文件:
spring.datasource: druid: url: jdbc:mysql://127.0.0.1:3306/xueluo?useUnicode=true username: ENC(SMZ qN 4u965ME2dwarUSg==) password: ENC(QHRGcpI4YUtB6a6VQCpIFg==)
注意: pom文件也需要进行配置哦:
<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot</artifactId>
<version>2.0.0</version>
</dependency>
主启动类配置注解:
@EnableEncryptableProperties
齐活儿了~~
想验证加密正确性,可以使用
System.out.println(encryptor.decrypt("SMZ+qN+4u965ME2dwarUSg=="));