jasypt加密

  • Post author:
  • Post category:其他


配置依赖

<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot-starter</artifactId>
    <version>1.16</version>
</dependency>
<dependency>
    <groupId>com.github.ulisesbocchio</groupId>
    <artifactId>jasypt-spring-boot</artifactId>
    <version>2.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jasypt/jasypt -->
<dependency>
    <groupId>org.jasypt</groupId>
    <artifactId>jasypt</artifactId>
    <version>1.9.3</version>
</dependency>

配置文件配置;配置加密所需的salt(盐),然后需要加密的配置用ENC(密文)的形式配置

#加密所需要的盐
jasypt.encryptor.password=your salt

# 解密得到原始密码
spring.datasource.password= ENC(密文)

得到密文

import org.jasypt.util.text.BasicTextEncryptor;

public static void main(String[] args) {
    BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
    //加密所需的salt(盐)
    textEncryptor.setPassword("AFfYkitulv45IsskmXI50JMXoaxZTKJ6");
    //要加密的数据(数据库的用户名或密码)
    String username = textEncryptor.encrypt("root");
    String password = textEncryptor.encrypt("root123");

    //解密
    String user = textEncryptor.decrypt("Yf7YaiqdDaNppOwmKfi+qw==");
    System.out.println("username:"+username);
    System.out.println("password:"+password);
    System.out.println("user:"+user);
}



版权声明:本文为qq_37634156原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。