Commit 2c8a3773 authored by AfirSraftGarrier's avatar AfirSraftGarrier

格式并加些打印

parent d7049cf1
......@@ -47,7 +47,7 @@ public class DeviceControllerTest {
String sign = HmacUtil.encrypt(string, appKey, HmacUtil.HMAC_SHA1);
// 组装
AuthData authData = new AuthData();
authData.setAppId(appId);
authData.setApp_id(appId);
authData.setSn(sn);
authData.setSign(sign);
byte[] dataBytes = encryptData_ECB(JSON.toJSONString(authData), sm4KeyBytes);
......@@ -112,47 +112,6 @@ public class DeviceControllerTest {
@Test
void authDevice() {
byte[] stxBytes = {(byte) 0x55, (byte) 0xaa};
// 数据处理过程
// 先随机16组
///**
// * 取随机数生成新key
// */
//for(i=0;i<4;i++)
//{
//*((unsigned int *)(&rand_data[i*4]))=rand()&0xffffffff;
//}
//
//for(i=0;i<16;i++)
//{
// new_key[i]=rand_data[i]^base_key[i];
//}
AuthData authData = new AuthData();
authData.setAppId("sdfd");
authData.setSn("sdf");
authData.setSign("sdf");
byte[] dataBytes = JSON.toJSONString(authData).getBytes();
int length = dataBytes.length + stxBytes.length;
byte[] lenBytes = {(byte) length, (byte) (length >> 8)};
byte cmdByte = (byte) 0x01;
byte ackByte = (byte) 0x00;
byte endByte = (byte) 0x00;
// 加密最后字段
endByte = (byte) (endByte ^ cmdByte);
endByte = (byte) (endByte ^ ackByte);
for (int i = 0; i < length - 2; i++) {
endByte = (byte) (endByte ^ dataBytes[i]);
}
byte[] allBytes = byteMerger(stxBytes, lenBytes, new byte[]{cmdByte, ackByte}, dataBytes, new byte[]{endByte});
System.out.println(bytes2Hex(allBytes));
}
public static byte[] byteMerger(byte[]... byteList) {
......
......@@ -9,7 +9,7 @@ import lombok.Data;
*/
@Data
public class AuthData {
private String appId;
private String app_id;
private String sn;
private String sign;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment