diff --git a/spring-boot-demo-email/README.md b/spring-boot-demo-email/README.md index a3bdd47..08e70db 100644 --- a/spring-boot-demo-email/README.md +++ b/spring-boot-demo-email/README.md @@ -83,8 +83,8 @@ spring: host: smtp.mxhichina.com port: 465 username: spring-boot-demo@xkcoding.com - # 使用 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 diff --git a/spring-boot-demo-email/src/main/resources/application.yml b/spring-boot-demo-email/src/main/resources/application.yml index 28feaca..719815b 100644 --- a/spring-boot-demo-email/src/main/resources/application.yml +++ b/spring-boot-demo-email/src/main/resources/application.yml @@ -3,8 +3,8 @@ spring: host: smtp.mxhichina.com port: 465 username: spring-boot-demo@xkcoding.com - # 使用 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 diff --git a/spring-boot-demo-email/src/test/java/com/xkcoding/email/PasswordTest.java b/spring-boot-demo-email/src/test/java/com/xkcoding/email/PasswordTest.java new file mode 100644 index 0000000..d6c0955 --- /dev/null +++ b/spring-boot-demo-email/src/test/java/com/xkcoding/email/PasswordTest.java @@ -0,0 +1,34 @@ +package com.xkcoding.email; + +import org.jasypt.encryption.StringEncryptor; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +/** + *

+ * 数据库密码测试 + *

+ * + * @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); + } +}