Code Monkey home page Code Monkey logo

encrypt-env-spring-boot-starter's Introduction

encrypt-env-spring-boot-starter

使用场景

在Spring Boot中,配置参数使用明文的方式造成敏感信息泄露,例如:

spring:
  datasource:
    username: admin
    password: admin
    url: jdbc:mysql://127.0.0.1:3306

现在,可以使用encrypt-env-spring-boot-starter可以对配置信息进行脱敏处理,避免了因为不安全的因素将敏感数据泄露。遵循spring-boot-starter的通用starter配置方式,开箱即用。

spring:
  datasource:
    username: enc:twGrVRJ60ACdcY0JFP/gbQ==
    # or username: "{enc:twGrVRJ60ACdcY0JFP/gbQ==}"
    password: enc:KsaeJD9ahUNJtR8yR8koJw==
    # or password: "{enc:KsaeJD9ahUNJtR8yR8koJw==}"
    url: enc:fas0AsdsfafJFP/adaewff
    # or url: "abc{enc:fas0AsdsfafJFP/adaewff}cba"

使用方式

  1. 引入
implementation 'com.xiaohaoo:encrypt-env-spring-boot-starter:1.1.0'
<dependency>
    <groupId>com.xiaohaoo</groupId>
    <artifactId>encrypt-env-spring-boot-starter</artifactId>
    <version>1.1.0</version>
</dependency>
  1. 配置

对配置文件中的敏感数据进行加密后添加前缀 enc: 或者使用 {enc:密文} 即可。

spring:
  datasource:
    username: enc:twGrVRJ60ACdcY0JFP/gbQ==
    # or username: "{enc:twGrVRJ60ACdcY0JFP/gbQ==}"
    password: enc:KsaeJD9ahUNJtR8yR8koJw==
    # or password: "{enc:KsaeJD9ahUNJtR8yR8koJw==}"
    url: enc:fas0AsdsfafJFP/adaewff
    # or url: "abc{enc:fas0AsdsfafJFP/adaewff}cba"
  1. 获取加密字符串
public class EncryptEnvApplicationTests {

    @Test
    void encrypt() {
        // 对称加密秘钥
        SecretHandler aesSecretResolve = new AesSecretHandler("xiaohaoo");
        // 要加密的字符串
        System.out.println(aesSecretResolve.encrypt("spring boot"));
    }
}

加密方法

计划支持:

  • AES
  • DES
  • RSA

encrypt-env-spring-boot-starter's People

Contributors

xiaohaoo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.