今天突然发现一个可以在连接数据库的时候将配置加密的东西,在此分享给广大朋友
- 首先我们导入相关的依赖
<!--加密工具--> <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
- 最后我们进行测试
- 查询成功
- 在此记录一次学习的一个过程
热门文章
- vue3 setup如何使用props
- 动物疫苗在哪里买便宜些(动物疫苗经销商)
- 3月20日 - 最高速度22.7M/S,2025年Surfboard每天更新免费节点订阅链接,干净IP机场推荐
- 中国动物疫苗10强企业名单公布(中国动物疫苗十强上市公司)
- Mysql模糊查询区分大小写
- 宠物领养协议文案简短范文 宠物领养协议文案简短范文大全
- HCNP Routing&Switching之Super VLAN_在线工具
- 3月13日 - 最高速度23M/S,2025年Surfboard每天更新免费节点订阅链接,干净IP机场推荐
- JavaScript如何将字符串的字母映射到数组的对象
- C ++中二进制矩阵的最短路径