forked from xkcoding/spring-boot-demo
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,8 +83,8 @@ spring: | |
host: smtp.mxhichina.com | ||
port: 465 | ||
username: [email protected] | ||
# 使用 jasypt 加密密码 | ||
password: ENC(6XYNBOJrcmAOiNqZiVaqw/ff8rjusN2H) | ||
# 使用 jasypt 加密密码,使用com.xkcoding.email.PasswordTest.testGeneratePassword 生成加密密码,替换 ENC(加密密码) | ||
password: ENC(OT0qGOpXrr1Iog1W+fjOiIDCJdBjHyhy) | ||
protocol: smtp | ||
test-connection: true | ||
default-encoding: UTF-8 | ||
|
@@ -98,6 +98,7 @@ spring: | |
jasypt: | ||
encryptor: | ||
password: spring-boot-demo | ||
|
||
``` | ||
|
||
## MailService.java | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ spring: | |
host: smtp.mxhichina.com | ||
port: 465 | ||
username: [email protected] | ||
# 使用 jasypt 加密密码 | ||
password: ENC(6XYNBOJrcmAOiNqZiVaqw/ff8rjusN2H) | ||
# 使用 jasypt 加密密码,使用com.xkcoding.email.PasswordTest.testGeneratePassword 生成加密密码,替换 ENC(加密密码) | ||
password: ENC(OT0qGOpXrr1Iog1W+fjOiIDCJdBjHyhy) | ||
protocol: smtp | ||
test-connection: true | ||
default-encoding: UTF-8 | ||
|
34 changes: 34 additions & 0 deletions
34
spring-boot-demo-email/src/test/java/com/xkcoding/email/PasswordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.xkcoding.email; | ||
|
||
import org.jasypt.encryption.StringEncryptor; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* <p> | ||
* 数据库密码测试 | ||
* </p> | ||
* | ||
* @author yangkai.shen | ||
* @date Created in 2019/8/27 16:15 | ||
*/ | ||
public class PasswordTest extends SpringBootDemoEmailApplicationTests { | ||
@Autowired | ||
private StringEncryptor encryptor; | ||
|
||
/** | ||
* 生成加密密码 | ||
*/ | ||
@Test | ||
public void testGeneratePassword() { | ||
// 你的邮箱密码 | ||
String password = "Just4Test!"; | ||
// 加密后的密码(注意:配置上去的时候需要加 ENC(加密密码)) | ||
String encryptPassword = encryptor.encrypt(password); | ||
String decryptPassword = encryptor.decrypt(encryptPassword); | ||
|
||
System.out.println("password = " + password); | ||
System.out.println("encryptPassword = " + encryptPassword); | ||
System.out.println("decryptPassword = " + decryptPassword); | ||
} | ||
} |