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

This commit is contained in:
junj2.liang 2022-08-31 15:10:43 +08:00
parent 86a784c1ba
commit 009ed41fc3

View File

@ -46,7 +46,7 @@ public class SydApiSM4 {
//加密 //加密
if (plength < 16) { if (plength < 16) {
api.SYD_SM4_LongData(iKeyIndex, new byte[0], iPkgNum, iFlag); api.SYD_SM4_LongData(iKeyIndex, new byte[0], iPkgNum, iFlag);
if (iFlag == 0 && 1 == iKeyIndex) { if (iFlag == 0 && 1 == iPkgNum) {
throw new SydApiException("解密的首包不能小于 16 字节", 0); throw new SydApiException("解密的首包不能小于 16 字节", 0);
} }
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength); ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
@ -68,7 +68,7 @@ public class SydApiSM4 {
sourceWrap = bufferResult; sourceWrap = bufferResult;
} }
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag); byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
iKeyIndex = 2; iPkgNum = 2;
} else { } else {
if (16 > pcData.length + sourceWrap.array().length) { if (16 > pcData.length + sourceWrap.array().length) {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength); ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
@ -83,7 +83,6 @@ public class SydApiSM4 {
api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag); api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag);
} }
else { else {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength); ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
bufferResult.put(sourceWrap); bufferResult.put(sourceWrap);
bufferResult.put(pcData); bufferResult.put(pcData);
@ -117,7 +116,7 @@ public class SydApiSM4 {
} }
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag); byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
sourceWrap = null; // sourceWrap = null;
return bytes; return bytes;
} }
public ByteBuffer bufferResult(int plength,byte[] pcData){ public ByteBuffer bufferResult(int plength,byte[] pcData){