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

  • 相关阅读:
    派生类的构造函数
    继承和派生
    自增自减运算符的重载(强制类型转换运算符重载)
    流插入和流提取运算符的重载
    动态数组类的设计
    函数的返回值
    赋值运算符的重载
    运算符重载
    常量对象函数引用和参数传递
    理解ASP.NET MVC的路由系统
  • 原文地址:https://www.cnblogs.com/xuchen0117/p/14375211.html
Copyright © 2011-2022 走看看