使用jasypt对springboot的datasource密码加密

1.Maven 依赖

        
        <dependency>
            <groupId>com.github.ulisesbocchiogroupId>
            <artifactId>jasypt-spring-boot-starterartifactId>
            <version>1.8version>
        dependency>

2.配置加密参数(可以理解为加密的salt)

jasypt:
  encryptor:
    password: BdaObXaELAA   #(或者用123456)

3.使用加密
(这里需要注意 BfsoZM9dAAU4lVp+pE47Y/0N9fqcci1A 为加密后的字符串 需要放到ENC里面)

datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/saas_official_document?useUnicode=true&characterEncoding=utf8
    username: appuser
    password: ENC(BfsoZM9dAAU4lVp+pE47Y/0N9fqcci1A)

4.加密密码

public class JasypTest {


    @Autowired
    StringEncryptor stringEncryptor;

    @Test
    public void encryptPwd() {
        String result = stringEncryptor.encrypt("your paasword 123456");
        System.out.println(result); 
    }
}

你可能感兴趣的:(spring-boot)