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

  • 相关阅读:
    Leetcode 238. Product of Array Except Self
    Leetcode 103. Binary Tree Zigzag Level Order Traversal
    Leetcode 290. Word Pattern
    Leetcode 205. Isomorphic Strings
    Leetcode 107. Binary Tree Level Order Traversal II
    Leetcode 102. Binary Tree Level Order Traversal
    三目运算符
    简单判断案例— 分支结构的应用
    用switch判断月份的练习
    java基本打印练习《我行我素购物系统》
  • 原文地址:https://www.cnblogs.com/xuchen0117/p/14375211.html
Copyright © 2011-2022 走看看