好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

在SpringBoot中通过jasypt进行加密解密的方法

1.用途

在springboot中,通过jasypt可以进行加密解密. 这个是双向的, 且可以配置密钥.

2.使用:

2.1通过ut创建工具类,并认识jasypt

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

import org.jasypt.util.text.basictextencryptor;

import org.junit.test;

public class utiltests {

   @test

   public void jasypttest() {

     basictextencryptor encryptor = new basictextencryptor();

     // application.properties, jasypt.encryptor.password

     encryptor.setpassword( "abc" );

     // encrypt root

     system.out.println(encryptor.encrypt( "root" ));

     system.out.println(encryptor.encrypt( "root" ));

     system.out.println(encryptor.encrypt( "root" ));

     // decrypt, the result is root

     system.out.println(encryptor.decrypt( "up/yojb7ie3apnh3mltu7w==" ));

     system.out.println(encryptor.decrypt( "ik9fe3giylihwchiyhg9qq==" ));

     system.out.println(encryptor.decrypt( "9obo/jq9eqmte0qzajfyrw==" ));

   }

}

可以看出, 每次生成的密码是不一样的, 但是通过密钥,可以解密成一样的明文.

2.2在springboot中配置jasypt

2.2.1配置密钥

jasypt.encryptor.password:abc

2.2.2使用

spring.datasource.url: jdbc:mysql://127.0.0.1:3306/tmp?usessl=false&useunicode=true&characterencoding=utf-8

spring.datasource.username: enc(ik9fe3giylihwchiyhg9qq==)

spring.datasource.password: enc(ik9fe3giylihwchiyhg9qq==)

spring.datasource.driver-class-name: com.mysql.jdbc.driver

2.2.3启动时配置密钥

java -jar -djasypt.encryptor.password=abc xxx.jar

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接

原文链接:https://blog.csdn.net/sanpic/article/details/82869058

查看更多关于在SpringBoot中通过jasypt进行加密解密的方法的详细内容...

  阅读:23次