为了加强数据库配置文件保密性,对application.yml进行了密码加密功能
实现步骤如下:
1.导入xml
<!-- 密码加密使用 -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
2.yml导入
jasypt:
encryptor:
password: erp
3.生成密钥
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { TbCloudApplication.class })
@Configuration
public class PasswordTester {
@Autowired
private StringEncryptor encryptor;
@Test
public void tester() {
System.err.println("sxnhtc-nh_bank-1 --> " + encryptor.encrypt("sxnhtc-nh_bank-1"));
System.err.println("1 --> " + encryptor.encrypt("1"));
}
}
4.yml配置:
password: ENC(ZEtU6okJXwEwzrA0a+TdQ0A4ME+8ehOUpopGSXie6ZQ=)