Fork me on GitLab

spring-boot加密解密敏感信息

spring-boot加密解密敏感信息

  导入pom依赖,jasypt可以在maven库中查看详情。

<dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>3.0.3</version>
        </dependency>

 在测试类中加密好字符cop到yml就行了

@Autowired
    private StringEncryptor stringEncryptor;

    @Test
    void contextLoads() {
        System.out.println(stringEncryptor.encrypt("root"));
        System.out.println(stringEncryptor.encrypt("123456"));
    }
spring:
  datasource:
    url: jdbc:mysql:///test? characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
    username: ENC(B1Zcu4HdB9dtSmPuGQ1TcsSRFh3+E/2IbRKTjBdFPR/WGeQTkIBauB+C4HGxA1NS)
    password: ENC(96PzPuehIXph7SUqFE8TwGzkJnUP5/NyE1Nlr3pq61S/uJJVsE/4Zvonrm4nEIEy)
    driver-class-name: com.mysql.cj.jdbc.Driver


  redis:
    host: localhost
    port: 6379
    password: ENC(96PzPuehIXph7SUqFE8TwGzkJnUP5/NyE1Nlr3pq61S/uJJVsE/4Zvonrm4nEIEy)


jasypt:
  encryptor:
    #加密秘钥
    password: fwafawkjnkjnkjsfjawjawhf
  #修改识别方式 #property: # prefix: svn-
  # 
suffix: -
 

 

posted @ 2021-03-04 10:51  隐琳琥  阅读(280)  评论(0编辑  收藏  举报