jasypt 对 配置文件密码进行加密处理

内容来源:https://blog.csdn.net/She_lock/article/details/84371215

jasypt由于其使用的是PBEWithMD5AndDES加密方式,所以每次加密出来的结果都不一样,所以很适合对数据进行加密

1、添加依赖

	<!-- jasypt 密码加密处理 -->
	<dependency>
	    <groupId>com.github.ulisesbocchio</groupId>
	    <artifactId>jasypt-spring-boot-starter</artifactId>
	    <version>2.1.1</version>
	</dependency>

  

2、编写加密方法

   public static void encrytion() {
             BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
             //加密所需的salt(盐)
             textEncryptor.setPassword("acbd123!");
             //要加密的数据(数据库的用户名或密码)
             String password = textEncryptor.encrypt("123456");
             
             //解密:
             //textEncryptor.decrypt("");
             
             System.out.println("password:"+password);
            
        }

 

3、在配置文件中写上jasypt  salt (盐)内容

jasypt:
  encryptor:
    password: acbd123!

  

4、将第二步得到的加密结果,写在数据库配置信息的password中,写法如下,(前面增加ENC,用括号把内容括起来)

password: ENC(DnHgQZbrx2+/S7xE11MXrw==)

  

posted @ 2020-11-05 17:57  路易蓝  阅读(1518)  评论(0编辑  收藏  举报