SecureApiTest.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package com.sqx;
  2. import com.google.gson.Gson;
  3. import com.sqx.modules.errand.entity.TransferRecordEntity;
  4. import com.sqx.modules.riderStation.entity.RiderStation;
  5. import icu.xuyijie.secureapi.cipher.CipherAlgorithmEnum;
  6. import icu.xuyijie.secureapi.cipher.CipherUtils;
  7. /**
  8. * @author : codingliang
  9. * @date : 2024-08-07 11:01
  10. */
  11. public class SecureApiTest {
  12. public static void main(String[] args) {
  13. test2();
  14. }
  15. public static void test2() {
  16. CipherUtils cipherUtils = new CipherUtils(CipherAlgorithmEnum.AES_CBC_PKCS5);
  17. // 生成 key
  18. // String key = cipherUtils.getRandomSecreteKey();
  19. // // 生成偏移量(CBC模式需要,ECB模式不需要)
  20. // String iv = cipherUtils.getRandomIv();
  21. //
  22. // System.out.println(key + " " + iv);
  23. // 生成 key
  24. String key = "oURKtBcNU6axnNoebKkuPqkCn6ivhE9qbg9FpeNnfpo=";
  25. // 生成偏移量(CBC模式需要,ECB模式不需要)
  26. String iv = "eW1xeThJSkprcEZUTGh1Ng==";
  27. String content = "{\"msg\":\"success\",\"code\":0,\"data\":{\"id\":579,\"userId\":2049,\"money\":1275.39}}";
  28. String encrypt = cipherUtils.encrypt(content, key, iv);
  29. System.out.println(encrypt);
  30. String decrypt = cipherUtils.decrypt("RPX3_v1bTP4fLfrEMWHegBp_pJPh8TGDaN-SHZFjyyK_HLRIAt_wQrgWX95ZeHDKoTgvtRYcMKaTRs5YHDXFZM9GChuubOvCkwygP1ubQl4=", key, iv);
  31. System.out.println(decrypt);
  32. }
  33. public static void test1() {
  34. CipherUtils cipherUtils = new CipherUtils(CipherAlgorithmEnum.AES_CBC_PKCS5, false);
  35. // 生成 key
  36. String key = "87OGRxGq86S9QO6HJSe78dK0CpuSFVz1TkhnkM/MjE0=";
  37. // 生成偏移量(CBC模式需要,ECB模式不需要)
  38. String iv = "UjNyWWxLOWxKTEgzNFFwZw==";
  39. String content = "{\"msg\":\"success\",\"code\":0,\"data\":{\"id\":579,\"userId\":2049,\"money\":1275.39}}";
  40. String encrypt = cipherUtils.encrypt(content, key, iv);
  41. System.out.println(encrypt);
  42. String decrypt = cipherUtils.decrypt(encrypt, key, iv);
  43. System.out.println(decrypt);
  44. }
  45. // dzUjvlKSwM2V3gg_l_dvGFKdJF84W9cBWQxXKM7NqzMNRAYdEsiF5DJ60iAzNKeDWgVRjR5X2-mqdlVVdEJ5BLfE3gA2lzWn73mnvHNq1R4=
  46. // dzUjvlKSwM2V3gg_l_dvGFKdJF84W9cBWQxXKM7NqzMNRAYdEsiF5DJ60iAzNKeDWgVRjR5X2-mqdlVVdEJ5BLfE3gA2lzWn73mnvHNq1R4=
  47. }