| @@ -83,8 +83,8 @@ spring: | |||||
| host: smtp.mxhichina.com | host: smtp.mxhichina.com | ||||
| port: 465 | port: 465 | ||||
| username: spring-boot-demo@xkcoding.com | username: spring-boot-demo@xkcoding.com | ||||
| # 使用 jasypt 加密密码 | |||||
| password: ENC(6XYNBOJrcmAOiNqZiVaqw/ff8rjusN2H) | |||||
| # 使用 jasypt 加密密码,使用com.xkcoding.email.PasswordTest.testGeneratePassword 生成加密密码,替换 ENC(加密密码) | |||||
| password: ENC(OT0qGOpXrr1Iog1W+fjOiIDCJdBjHyhy) | |||||
| protocol: smtp | protocol: smtp | ||||
| test-connection: true | test-connection: true | ||||
| default-encoding: UTF-8 | default-encoding: UTF-8 | ||||
| @@ -98,6 +98,7 @@ spring: | |||||
| jasypt: | jasypt: | ||||
| encryptor: | encryptor: | ||||
| password: spring-boot-demo | password: spring-boot-demo | ||||
| ``` | ``` | ||||
| ## MailService.java | ## MailService.java | ||||
| @@ -3,8 +3,8 @@ spring: | |||||
| host: smtp.mxhichina.com | host: smtp.mxhichina.com | ||||
| port: 465 | port: 465 | ||||
| username: spring-boot-demo@xkcoding.com | username: spring-boot-demo@xkcoding.com | ||||
| # 使用 jasypt 加密密码 | |||||
| password: ENC(6XYNBOJrcmAOiNqZiVaqw/ff8rjusN2H) | |||||
| # 使用 jasypt 加密密码,使用com.xkcoding.email.PasswordTest.testGeneratePassword 生成加密密码,替换 ENC(加密密码) | |||||
| password: ENC(OT0qGOpXrr1Iog1W+fjOiIDCJdBjHyhy) | |||||
| protocol: smtp | protocol: smtp | ||||
| test-connection: true | test-connection: true | ||||
| default-encoding: UTF-8 | default-encoding: UTF-8 | ||||
| @@ -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); | |||||
| } | |||||
| } | |||||