增加init/update/digest/finish长数据操作

This commit is contained in:
junj2.liang 2022-09-01 10:26:48 +08:00
parent e36985f20a
commit a5f38b4a8f
2 changed files with 13 additions and 13 deletions

View File

@ -12,6 +12,7 @@ public class SydApiSM4 {
private int iPkgNum = 1;
private int iFlag;
private boolean is_finished = false;
private byte[] dataResult = new byte[0];
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
@ -23,6 +24,7 @@ public class SydApiSM4 {
public byte[] update(byte[] pcData) {
this.pcdataResult = pcData;
// this.dataResult = pcData;
if (null == pcData || pcData.length == 0) {
return new byte[0];
}
@ -64,19 +66,19 @@ public class SydApiSM4 {
} else {
if (16 > pcData.length + sourceWrap.array().length) {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
bufferResult.put(sourceWrap.array());
bufferResult.put(pcData);
sourceWrap = bufferResult;
return new byte[0];
} else if ((pcData.length + sourceWrap.array().length) % 16 == 0) {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
bufferResult.put(sourceWrap.array());
bufferResult.put(pcData);
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
return api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag);
} else {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
bufferResult.put(sourceWrap.array());
bufferResult.put(pcData);
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
@ -107,8 +109,8 @@ public class SydApiSM4 {
this.iPkgNum = 3;
}
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
// sourceWrap = null;
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex,sourceWrap.array(), iPkgNum, iFlag);
sourceWrap = null;
return bytes;
}

View File

@ -21,7 +21,7 @@ public class SydSM4Mac {
this.api = api;
this.iKeyIndex = iKeyIndex;
this.pcProcData = pcProcData;
this.pcMac=pcMac;
// this.pcMac=pcMac;
}
public SydSM4Mac(SydApi api) {
@ -80,16 +80,14 @@ public class SydSM4Mac {
} else {
if (16 > (pcData.length + sourceWrap.array().length)) {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + pcData.length);
bufferResult.put(sourceWrap);
bufferResult.put(sourceWrap.array());
bufferResult.put(pcData);
sourceWrap = bufferResult;
}
else if (16<=(pcData.length + sourceWrap.array().length)&&(pcData.length + sourceWrap.array().length) % 16 == 0) {
int k2 = sourceWrap.array().length+pcData.length;
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + pcData.length);
byte[] bytes1 = bytebuffer2ByteArray(sourceWrap);
bufferResult.put(bytes1);
bufferResult.put(sourceWrap.array());
bufferResult.put(pcData);
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
if (null == this.pcMac || "".equals(this.pcMac)) {
@ -103,7 +101,7 @@ public class SydSM4Mac {
}
} else {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
bufferResult.put(bytebuffer2ByteArray(sourceWrap));
bufferResult.put(sourceWrap.array());
bufferResult.put(pcData);
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
@ -142,10 +140,10 @@ public class SydSM4Mac {
this.iPkgNum = 3;
}
if (null == this.pcMac || "".equals(this.pcMac)) {
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, this.pcdataResult, iPkgNum, pcProcData);
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, this.sourceWrap.array(), iPkgNum, pcProcData);
return stringStringLongDataReturn;
} else {
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, this.pcdataResult, iPkgNum, pcProcData, pcMac);
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, this.sourceWrap.array(), iPkgNum, pcProcData, pcMac);
return stringBooleanLongDataReturn;
}