写我的项目的时候总是会胆怯本人的数据库连贯信息泄露,所以记录一下加密的办法。

jasypt加密

1. 引入Maven依赖

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

2. application.yml

# 加密的密钥jasypt:  encryptor:    password: zhouzhaodong

3. 生成加密后的密钥

/**     * 明码解码器主动注入     */    @Autowired    StringEncryptor encryptor;    @Test    void test(){        String url = encryptor.encrypt("地址");        String name = encryptor.encrypt("用户名");        String password = encryptor.encrypt("明码");        System.out.println(url);        System.out.println(name);        System.out.println(password);    }

4. 对原数据进行替换即可

spring:  # 数据库连贯信息  datasource:    # 数据库地址    url: ENC(url生成的密钥)    # 用户名    username: ENC(用户名生成的密钥)    # 明码    password: ENC(明码生成的密钥)

集体博客地址:

http://www.zhouzhaodong.xyz/