PigxAdminApplicationTest.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2018-2025, lengleng All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the pig4cloud.com developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: lengleng (wangiegie@gmail.com)
  16. */
  17. package com.pig4cloud.pigx.admin;
  18. import com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor;
  19. import org.jasypt.encryption.StringEncryptor;
  20. import org.junit.Test;
  21. import org.springframework.core.env.StandardEnvironment;
  22. /**
  23. * @author lengleng
  24. * @date 2018/10/7
  25. * <p>
  26. * 加解密单元测试
  27. */
  28. public class PigxAdminApplicationTest {
  29. @Test
  30. public void testJasypt() {
  31. // 对应application-dev.yml 中配置的根密码
  32. System.setProperty("jasypt.encryptor.password", "pigx");
  33. StringEncryptor stringEncryptor = new DefaultLazyEncryptor(new StandardEnvironment());
  34. //加密方法
  35. System.out.println(stringEncryptor.encrypt("pigx"));
  36. //解密方法
  37. System.out.println(stringEncryptor.decrypt("ltJPpR50wT0oIY9kfOe1Iw==="));
  38. }
  39. }