|
|
@@ -0,0 +1,63 @@
|
|
|
+package com.tokheim.aifueling;
|
|
|
+
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import com.tokheim.aifueling.utils.ByteArrayUtils;
|
|
|
+import com.tokheim.aifueling.utils.SM4Utils;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@SpringBootTest
|
|
|
+class AiFuelingApplicationTests {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testSm4Encryption() {
|
|
|
+ byte[] bytes = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,0x11,0x12};
|
|
|
+ try {
|
|
|
+ byte[] resultBytes = SM4Utils.encrypt(bytes);
|
|
|
+ System.out.println(Convert.toHex(resultBytes));
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testSm4Decryption() {
|
|
|
+ byte[] bytes = {0x24,0x72,0x3f,0x04,0x24,0x1f, (byte) 0x88, (byte) 0xc4, (byte) 0xab,0x34,0x62, (byte) 0xf2,
|
|
|
+ (byte) 0xbc, (byte) 0x83, (byte) 0xac, (byte) 0x99, (byte) 0xce, 0x34,0x73, (byte) 0x9b, (byte) 0xaa,
|
|
|
+ 0x72, (byte) 0xdf,0x77,0x68, (byte) 0xb0,0x35, (byte) 0xa7,0x2e,0x0e,0x57};
|
|
|
+
|
|
|
+ try {
|
|
|
+ byte[] resultbytes = SM4Utils.decrypt(bytes);
|
|
|
+ System.out.println(Convert.toHex(resultbytes));
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testFindSubIndex(){
|
|
|
+ byte[] source = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
|
|
|
+ byte[] target = {0x02,0x03};
|
|
|
+ System.out.println(ByteArrayUtils.findSubarrayIndex(source,target));
|
|
|
+
|
|
|
+ byte[] source2 = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
|
|
|
+ byte[] target2 = {0x10,0x24};
|
|
|
+ System.out.println(ByteArrayUtils.findSubarrayIndex(source2,target2));
|
|
|
+
|
|
|
+ byte[] source3 = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
|
|
|
+ byte[] target3 = {0x02,0x03};
|
|
|
+ System.out.println(ByteArrayUtils.findSubarrayIndex(source3,target3));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void testBytes2Hex(){
|
|
|
+ byte[] bytes = {0x12,0x01,0x10, (byte) 0xaa, (byte) 0xff,0x00,0x1a,0x11, (byte) 0xab};
|
|
|
+ String s = ByteArrayUtils.bytesToHexString(bytes);
|
|
|
+ System.out.println(s);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|