From 9624ed3782df92e702d30a05b9666b005263bd2f Mon Sep 17 00:00:00 2001 From: "Yangkai.Shen" <237497819@qq.com> Date: Tue, 27 Aug 2019 16:30:16 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=9B=B4=E6=8D=A2demo=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E5=9C=B0=E5=9D=80=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E4=B8=8D=E8=83=BD=E4=BD=BF=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-boot-demo-email/README.md | 5 +-- .../src/main/resources/application.yml | 4 +-- .../java/com/xkcoding/email/PasswordTest.java | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 spring-boot-demo-email/src/test/java/com/xkcoding/email/PasswordTest.java 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); + } +}