From 1345fc9eed4ba69b4d3f4157cd9253f0d5e8abd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Sun, 30 Sep 2018 16:04:04 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81=E3=80=82=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=8A=A0=E8=A7=A3=E5=AF=86=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pig/admin/PigAdminApplicationTest.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/pig-modules/pig-upms-service/src/test/java/com/github/pig/admin/PigAdminApplicationTest.java b/pig-modules/pig-upms-service/src/test/java/com/github/pig/admin/PigAdminApplicationTest.java index 24c33bc6..24dd4dac 100644 --- a/pig-modules/pig-upms-service/src/test/java/com/github/pig/admin/PigAdminApplicationTest.java +++ b/pig-modules/pig-upms-service/src/test/java/com/github/pig/admin/PigAdminApplicationTest.java @@ -16,30 +16,31 @@ */ package com.github.pig.admin; + +import com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor; import org.jasypt.encryption.StringEncryptor; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.core.env.StandardEnvironment; -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = PigAdminApplication.class) +/** + * 配置文件加解密工具类 + * + * @author lengleng + */ public class PigAdminApplicationTest { - @Autowired - private StringEncryptor stringEncryptor; + private static final String JASYPT_ENCRYPTOR_PASSWORD = "jasypt.encryptor.password"; - @Test - public void testEnvironmentProperties() { -// System.out.println(stringEncryptor.encrypt("redis")); -// System.out.println(stringEncryptor.encrypt("pig")); - System.out.println(stringEncryptor.encrypt("lengleng")); - System.out.println(stringEncryptor.encrypt("root")); -// System.out.println(stringEncryptor.encrypt("g0HJr2Ltrs0k6tJDY6pDI2aVMUCPSWZDTROLcFMs")); -// System.out.println(stringEncryptor.encrypt("24760324")); -// System.out.println(stringEncryptor.encrypt("175d516debb916d3842d981dd3b76061")); -// System.out.println(stringEncryptor.encrypt("101322838")); -// System.out.println(stringEncryptor.encrypt("fe6ec1ed3fc45e664ce8ddbf78376ab7")); - } + /** + * jasypt.encryptor.password 对应 配置中心 application-dev.yml 中的密码 + */ + @Test + public void testEnvironmentProperties() { + System.setProperty(JASYPT_ENCRYPTOR_PASSWORD, "lengleng"); + StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment()); -} + //加密方法 + System.out.println(stringEncryptor.encrypt("123456")); + //解密方法 + System.out.println(stringEncryptor.decrypt("saRv7ZnXsNAfsl3AL9OpCQ==")); + } +} \ No newline at end of file