今天突然发现一个可以在连接数据库的时候将配置加密的东西,在此分享给广大朋友
- 首先我们导入相关的依赖
<!--加密工具--> <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>2.1.0</version> </dependency>
- 之后我们在测试类中编写加密解密
@Test void generateKey() { // 加密 BasicTextEncryptor encryptor = new BasicTextEncryptor(); encryptor.setPassword("abcd"); // 盐值 String username = encryptor.encrypt("root"); String password = encryptor.encrypt("1233"); System.out.println("username: " + username); System.out.println("password: " + password); System.out.println(encryptor.decrypt(username)); System.out.println(encryptor.decrypt(password)); }
- 结果
- 之后我们在yml中进行配置
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/jwt_security?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai username: ENC(otk4Os0hjRq3ui44sSUgsA==) password: ENC(glqH/F/UyBJ4s/eMnaGDRQ==) jasypt: encryptor: password: abcd #加密盐值 algorithm: PBEWithMD5AndDES #加密算法设置 iv-generator-classname: org.jasypt.iv.NoIvGenerator
- 最后我们进行测试
- 查询成功
- 在此记录一次学习的一个过程
热门文章
- 宠物食品加工厂要投资多少钱 宠物食品加工厂要投资多少钱呢
- Eureka的配置项详解
- 动物疫苗证在哪里办的呀(动物疫苗经营许可证在哪里办)
- 重庆宠物领养平台官网(重庆宠物领养中心宠物领养)
- 3月2日 | Clash Verge每天更新18.1M/S免费节点订阅链接地址
- 3月9日 | Clash Verge每天更新19.3M/S免费节点订阅链接地址
- 4月10日 | Clash Verge每天更新22.7M/S免费节点订阅链接地址
- 4月6日 | Clash Verge每天更新18.5M/S免费节点订阅链接地址
- 3月12日 | Clash Verge每天更新19M/S免费节点订阅链接地址
- 设计模式(9) 观察者模式