今天突然发现一个可以在连接数据库的时候将配置加密的东西,在此分享给广大朋友
<!--加密工具--> <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)); }
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