mirror of https://gitee.com/maxjhandsome/pig
✅ 添加测试代码。 配置文件加解密工具类使用
This commit is contained in:
parent
1ce016fcd6
commit
1345fc9eed
|
@ -16,30 +16,31 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.pig.admin;
|
package com.github.pig.admin;
|
||||||
|
|
||||||
|
import com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor;
|
||||||
import org.jasypt.encryption.StringEncryptor;
|
import org.jasypt.encryption.StringEncryptor;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
/**
|
||||||
@SpringBootTest(classes = PigAdminApplication.class)
|
* 配置文件加解密工具类
|
||||||
|
*
|
||||||
|
* @author lengleng
|
||||||
|
*/
|
||||||
public class PigAdminApplicationTest {
|
public class PigAdminApplicationTest {
|
||||||
@Autowired
|
private static final String JASYPT_ENCRYPTOR_PASSWORD = "jasypt.encryptor.password";
|
||||||
private StringEncryptor stringEncryptor;
|
|
||||||
|
|
||||||
@Test
|
/**
|
||||||
public void testEnvironmentProperties() {
|
* jasypt.encryptor.password 对应 配置中心 application-dev.yml 中的密码
|
||||||
// System.out.println(stringEncryptor.encrypt("redis"));
|
*/
|
||||||
// System.out.println(stringEncryptor.encrypt("pig"));
|
@Test
|
||||||
System.out.println(stringEncryptor.encrypt("lengleng"));
|
public void testEnvironmentProperties() {
|
||||||
System.out.println(stringEncryptor.encrypt("root"));
|
System.setProperty(JASYPT_ENCRYPTOR_PASSWORD, "lengleng");
|
||||||
// System.out.println(stringEncryptor.encrypt("g0HJr2Ltrs0k6tJDY6pDI2aVMUCPSWZDTROLcFMs"));
|
StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment());
|
||||||
// System.out.println(stringEncryptor.encrypt("24760324"));
|
|
||||||
// System.out.println(stringEncryptor.encrypt("175d516debb916d3842d981dd3b76061"));
|
|
||||||
// System.out.println(stringEncryptor.encrypt("101322838"));
|
|
||||||
// System.out.println(stringEncryptor.encrypt("fe6ec1ed3fc45e664ce8ddbf78376ab7"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
//加密方法
|
||||||
|
System.out.println(stringEncryptor.encrypt("123456"));
|
||||||
|
//解密方法
|
||||||
|
System.out.println(stringEncryptor.decrypt("saRv7ZnXsNAfsl3AL9OpCQ=="));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue