|
|
@@ -0,0 +1,57 @@
|
|
|
+package com.sqx;
|
|
|
+
|
|
|
+import icu.xuyijie.secureapi.cipher.CipherAlgorithmEnum;
|
|
|
+import icu.xuyijie.secureapi.cipher.CipherUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * TODO
|
|
|
+ *
|
|
|
+ * @author : codingliang
|
|
|
+ * @date : 2024-08-07 11:01
|
|
|
+ */
|
|
|
+public class SecureApiTest {
|
|
|
+ public static void main(String[] args) {
|
|
|
+ test2();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void test2() {
|
|
|
+ CipherUtils cipherUtils = new CipherUtils(CipherAlgorithmEnum.AES_CBC_PKCS5);
|
|
|
+
|
|
|
+ // 生成 key
|
|
|
+ // String key = cipherUtils.getRandomSecreteKey();
|
|
|
+ // // 生成偏移量(CBC模式需要,ECB模式不需要)
|
|
|
+ // String iv = cipherUtils.getRandomIv();
|
|
|
+ //
|
|
|
+ // System.out.println(key + " " + iv);
|
|
|
+
|
|
|
+ // 生成 key
|
|
|
+ String key = "oURKtBcNU6axnNoebKkuPqkCn6ivhE9qbg9FpeNnfpo=";
|
|
|
+ // 生成偏移量(CBC模式需要,ECB模式不需要)
|
|
|
+ String iv = "eW1xeThJSkprcEZUTGh1Ng==";
|
|
|
+
|
|
|
+ String content = "{\"msg\":\"success\",\"code\":0,\"data\":{\"id\":579,\"userId\":2049,\"money\":1275.39}}";
|
|
|
+ String encrypt = cipherUtils.encrypt(content, key, iv);
|
|
|
+ System.out.println(encrypt);
|
|
|
+
|
|
|
+ String decrypt = cipherUtils.decrypt("RPX3_v1bTP4fLfrEMWHegBp_pJPh8TGDaN-SHZFjyyK_HLRIAt_wQrgWX95ZeHDKoTgvtRYcMKaTRs5YHDXFZM9GChuubOvCkwygP1ubQl4=", key, iv);
|
|
|
+ System.out.println(decrypt);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void test1() {
|
|
|
+ CipherUtils cipherUtils = new CipherUtils(CipherAlgorithmEnum.AES_CBC_PKCS5, false);
|
|
|
+
|
|
|
+ // 生成 key
|
|
|
+ String key = "87OGRxGq86S9QO6HJSe78dK0CpuSFVz1TkhnkM/MjE0=";
|
|
|
+ // 生成偏移量(CBC模式需要,ECB模式不需要)
|
|
|
+ String iv = "UjNyWWxLOWxKTEgzNFFwZw==";
|
|
|
+
|
|
|
+ String content = "{\"msg\":\"success\",\"code\":0,\"data\":{\"id\":579,\"userId\":2049,\"money\":1275.39}}";
|
|
|
+ String encrypt = cipherUtils.encrypt(content, key, iv);
|
|
|
+ System.out.println(encrypt);
|
|
|
+
|
|
|
+ String decrypt = cipherUtils.decrypt(encrypt, key, iv);
|
|
|
+ System.out.println(decrypt);
|
|
|
+ }
|
|
|
+ // dzUjvlKSwM2V3gg_l_dvGFKdJF84W9cBWQxXKM7NqzMNRAYdEsiF5DJ60iAzNKeDWgVRjR5X2-mqdlVVdEJ5BLfE3gA2lzWn73mnvHNq1R4=
|
|
|
+ // dzUjvlKSwM2V3gg_l_dvGFKdJF84W9cBWQxXKM7NqzMNRAYdEsiF5DJ60iAzNKeDWgVRjR5X2-mqdlVVdEJ5BLfE3gA2lzWn73mnvHNq1R4=
|
|
|
+}
|