SpringBoot数据库加密

数据安全考虑数据库账号密码做个加密处理

添加依赖库

    <!--数据库加密-->
        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

添加key

jasypt.encryptor.password=EbfYkitulv73I2p0mXI50JMXoaxZT55

值可以随便改。

生成加密字符串

package com.example.modeltree.controller;

import com.example.modeltree.ModeltreeApplication;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: modeltree
 * @description:
 * @author: created by Gaohuahui
 * @create: 2022-01-11 14:43
 **/
@Api(tags = "密码")
@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    StringEncryptor encryptor;

    @GetMapping("/get")
    @ApiOperation(value = "get", notes = "get")
    @ResponseBody
    public void test() {
        String username = encryptor.encrypt("root");
        System.out.println(username);
        String password = encryptor.encrypt("123");
        System.out.println(password);
    }


}

请求接口打印生成密钥,修改配置文件即可

#用户名
spring.datasource.username=ENC(X3C/6C4lu6iv34NN5jsMWWGKyUE8+ZnoobDAA8575JKGnvPWa5NYcAiSq1/pZSzo)
#密码
spring.datasource.password=ENC(445VNaUSM8IEuT+FzCWJR23ToXXcj5Wlni/jPX5EEZ9PZ+zZ3O74240nE+q5/WYr)

问题:

 手动测试可以关闭手动测试可以关闭

 

 可以加上

<plugin><!--编译跳过测试文件检查的生命周期-->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

参考文档

springboot中数据库配置加密_heiyouling_51CTO博客

Maven 编译:Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date]_Crazy的博客-CSDN博客

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值