內容來源: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==)