Jasypt加密SpringBoot配置文件
pom(老版本差异好像还蛮大的)
<!--jasypt配置文件加解密--> <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>2.1.0</version> </dependency>
yml配置根密码
jasypt: encryptor: password: wildcat #根密码
yml中使用(固定格式ENC(密文))
spring: # 安全配置 security: user: name: ENC(gaiuHRaj6eRakPNkXa9kVw==) # wild password: ENC(bQyUuazTqczzA0GNhc/HPg==) # wild
单元测试
@Test public void testJasypt() { // 对应application.yml 中配置的根密码 System.setProperty("jasypt.encryptor.password", "wild"); StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment()); //加密方法 System.out.println(stringEncryptor.encrypt("wild")); //解密方法 System.out.println(stringEncryptor.decrypt("F8SqEhyyrciqcBvIwU2Prw==")); }
版权声明:本文为qq_22515647原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。