zoukankan      html  css  js  c++  java
  • springboot项目通过jasypt-spring-boot-starter加密配置

    1、pom.xml文件中加入

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

    2、密文的生成

    package com.xc.luckysheet.utils;
    
    
    import org.jasypt.util.text.BasicTextEncryptor;
    
    /**
     * jasypt-spring-boot-starter 生成密文的工具代码
     * @author cr
     */
    public class EncryptConfigUtil {
        public static void main(String[] args) {
    
            BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
            //加密所需的salt
            textEncryptor.setPassword("123456");
            //要加密的数据(数据库的用户名或密码)
            String username = textEncryptor.encrypt("root");
            String password = textEncryptor.encrypt("123456");
            System.out.println("username:"+username);
            System.out.println("password:"+password);
        }
    }

    3、修改配置文件

    spring:
      redis:
        host: 192.168.0.1
        port: 15556
        password: ENC(r6YJrfKMAAzzltzmEpEYv7lzYINULq6g)
        timeout: 10000ms
        lettuce:
          pool:
            max-active: 8
            max-wait: -1ms
            max-idle: 8
            min-idle: 0
        database: 0
    
    db:
      mysql:
        druid:
          url: jdbc:mysql://192.168.0.1:3307/luckysheetdb?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
          driverClassName: com.mysql.cj.jdbc.Driver
          username: ENC(opGC8sQt5JVH3j4VD5i2Ug)
          password: ENC(r6YUrfKMAAzzltzmApEYv7lZyILULq==)

    4、使用

    可配置在application.yml文件中(这种方式不安全)

    jasypt.encryptor.password=123456

    推荐在JVM启动参数中设置

    在idea中配置如下:

    -Djasypt.encryptor.password=123456

  • 相关阅读:
    搭建Nginx反向代理做内网域名转发
    网站监测脚本
    Nginx启动脚本
    L2TP用户添加和删除、搜索脚本
    CentOS Linux 安装IPSec+L2TP
    Nginx认证
    Nginx配置HTTPS
    Nginx 如何处理一个请求
    HTTP协议原理
    DNS解析流程
  • 原文地址:https://www.cnblogs.com/xuchen0117/p/14375211.html
Copyright © 2011-2022 走看看