debug
This commit is contained in:
parent
fde8ad86e9
commit
7620c538ae
@ -12,7 +12,7 @@ public class SydApiSM4 {
|
|||||||
private int iPkgNum = 1;
|
private int iPkgNum = 1;
|
||||||
private int iFlag;
|
private int iFlag;
|
||||||
private boolean is_finished = false;
|
private boolean is_finished = false;
|
||||||
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
private ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
||||||
|
|
||||||
|
|
||||||
public SydApiSM4(SydApi api, int iKeyIndex, int endeFlag) {
|
public SydApiSM4(SydApi api, int iKeyIndex, int endeFlag) {
|
||||||
@ -21,77 +21,87 @@ public class SydApiSM4 {
|
|||||||
this.iKeyIndex = iKeyIndex;
|
this.iKeyIndex = iKeyIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(byte[] pcData) {
|
public byte[] update(byte[] pcData) {
|
||||||
this.pcdataResult = pcData;
|
try {
|
||||||
if (null == pcData || pcData.length == 0) {
|
this.pcdataResult = pcData;
|
||||||
return;
|
if (null == pcData || pcData.length == 0) {
|
||||||
}
|
return new byte[0];
|
||||||
int plength = pcData.length;
|
}
|
||||||
if (is_finished) {
|
int plength = pcData.length;
|
||||||
throw new SydApiException(0);
|
if (is_finished) {
|
||||||
}
|
throw new SydApiException(0);
|
||||||
if (plength > 4064) {
|
}
|
||||||
throw new SydApiException(0);
|
if (plength > 4064) {
|
||||||
}
|
throw new SydApiException(0);
|
||||||
if (0 == sourceWrap.array().length) {
|
}
|
||||||
//加密
|
if (0 == sourceWrap.array().length) {
|
||||||
if (plength < 16) {
|
//加密
|
||||||
api.SYD_SM4_LongData(iKeyIndex, new byte[0], iPkgNum, iFlag);
|
if (plength < 16) {
|
||||||
if (iFlag == 0 && 1 == iPkgNum) {
|
api.SYD_SM4_LongData(iKeyIndex, new byte[0], iPkgNum, iFlag);
|
||||||
throw new SydApiException("解密的首包不能小于 16 字节", 0);
|
if (iFlag == 0 && 1 == iPkgNum) {
|
||||||
|
throw new SydApiException("解密的首包不能小于 16 字节", 0);
|
||||||
|
}
|
||||||
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
||||||
|
bufferResult.put(sourceWrap);
|
||||||
|
bufferResult.put(pcData);
|
||||||
|
sourceWrap = bufferResult;
|
||||||
|
}
|
||||||
|
if (plength % 16 != 0) {
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(pcData);
|
||||||
|
int remainder = plength % 16;
|
||||||
|
int intercept = plength - remainder;
|
||||||
|
byte[] bytes = new byte[intercept];
|
||||||
|
ByteBuffer byteBuffer = buffer.get(bytes, 0, intercept);
|
||||||
|
byte[] bytes1 = new byte[remainder];
|
||||||
|
byteBuffer.get(bytes1);
|
||||||
|
this.pcdataResult = bytes;
|
||||||
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + remainder);
|
||||||
|
bufferResult.put(bytes1);
|
||||||
|
sourceWrap = bufferResult;
|
||||||
}
|
}
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
|
||||||
bufferResult.put(sourceWrap);
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
sourceWrap = bufferResult;
|
|
||||||
}
|
|
||||||
if (plength % 16 != 0) {
|
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(pcData);
|
|
||||||
int remainder = plength % 16;
|
|
||||||
int intercept = plength - remainder;
|
|
||||||
byte[] bytes = new byte[intercept];
|
|
||||||
ByteBuffer byteBuffer = buffer.get(bytes, 0, intercept);
|
|
||||||
byte[] bytes1 = new byte[remainder];
|
|
||||||
byteBuffer.get(bytes1);
|
|
||||||
this.pcdataResult = bytes;
|
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + remainder);
|
|
||||||
bufferResult.put(bytes1);
|
|
||||||
sourceWrap = bufferResult;
|
|
||||||
}
|
|
||||||
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
|
||||||
iPkgNum = 2;
|
|
||||||
} else {
|
|
||||||
if (16 > pcData.length + sourceWrap.array().length) {
|
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
|
||||||
bufferResult.put(sourceWrap);
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
sourceWrap = bufferResult;
|
|
||||||
} else if ((pcData.length + sourceWrap.array().length) % 16 == 0) {
|
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
|
||||||
bufferResult.put(sourceWrap);
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
|
||||||
api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag);
|
|
||||||
} else {
|
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
|
||||||
bufferResult.put(sourceWrap);
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
|
||||||
int remainder = bytes.length % 16;
|
|
||||||
int intercept = bytes.length - remainder;
|
|
||||||
byte[] pcdataByte = new byte[intercept];
|
|
||||||
ByteBuffer byteBuffer = buffer.get(pcdataByte, 0, intercept);
|
|
||||||
byte[] bytes1 = new byte[remainder];
|
|
||||||
byteBuffer.get(bytes1);
|
|
||||||
this.pcdataResult = pcdataByte;
|
|
||||||
ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
|
|
||||||
bufferResults.put(bytes1);
|
|
||||||
sourceWrap = bufferResults;
|
|
||||||
api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
|
||||||
iPkgNum = 2;
|
iPkgNum = 2;
|
||||||
|
return api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (16 > pcData.length + sourceWrap.array().length) {
|
||||||
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
||||||
|
bufferResult.put(sourceWrap);
|
||||||
|
bufferResult.put(pcData);
|
||||||
|
sourceWrap = bufferResult;
|
||||||
|
} else if ((pcData.length + sourceWrap.array().length) % 16 == 0) {
|
||||||
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
||||||
|
bufferResult.put(sourceWrap);
|
||||||
|
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(sourceWrap);
|
||||||
|
bufferResult.put(pcData);
|
||||||
|
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
||||||
|
int remainder = bytes.length % 16;
|
||||||
|
int intercept = bytes.length - remainder;
|
||||||
|
byte[] pcdataByte = new byte[intercept];
|
||||||
|
ByteBuffer byteBuffer = buffer.get(pcdataByte, 0, intercept);
|
||||||
|
byte[] bytes1 = new byte[remainder];
|
||||||
|
byteBuffer.get(bytes1);
|
||||||
|
this.pcdataResult = pcdataByte;
|
||||||
|
ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
|
||||||
|
bufferResults.put(bytes1);
|
||||||
|
sourceWrap = bufferResults;
|
||||||
|
iPkgNum = 2;
|
||||||
|
return api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] finish() {
|
public byte[] finish() {
|
||||||
|
|||||||
@ -3,25 +3,22 @@ package com.sunyard.sge.database;
|
|||||||
import com.sunyard.SydApiException;
|
import com.sunyard.SydApiException;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
|
|
||||||
public class SydSM4Mac {
|
public class SydSM4Mac {
|
||||||
private SydApi api;
|
private SydApi api;
|
||||||
private byte[] last_in_data;
|
|
||||||
private int iKeyIndex;
|
private int iKeyIndex;
|
||||||
private int iPkgNum = 1;
|
private int iPkgNum = 1;
|
||||||
|
private boolean isFinished;
|
||||||
|
|
||||||
|
// 中间数据
|
||||||
private String pcProcData;
|
private String pcProcData;
|
||||||
private boolean is_finished;
|
|
||||||
private String pcMac;
|
|
||||||
private byte[] pcdataResult = new byte[0];
|
private ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
||||||
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
|
||||||
|
|
||||||
public SydSM4Mac(SydApi api, int iKeyIndex) {
|
public SydSM4Mac(SydApi api, int iKeyIndex) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.iKeyIndex = iKeyIndex;
|
this.iKeyIndex = iKeyIndex;
|
||||||
this.pcProcData = pcProcData;
|
|
||||||
this.pcMac=pcMac;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SydSM4Mac(SydApi api) {
|
public SydSM4Mac(SydApi api) {
|
||||||
@ -29,90 +26,47 @@ public class SydSM4Mac {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SydSM4Mac update(byte[] pcData) {
|
public SydSM4Mac update(byte[] pcData) {
|
||||||
if (null == pcData || 0 == pcData.length) {
|
|
||||||
return this;
|
try {
|
||||||
}
|
if (null == pcData || 0 == pcData.length) {
|
||||||
int length = pcData.length;
|
return this;
|
||||||
this.pcdataResult = pcData;
|
}
|
||||||
if (is_finished) {
|
int length = pcData.length;
|
||||||
throw new SydApiException(0);
|
this.pcdataResult = pcData;
|
||||||
}
|
if (isFinished) {
|
||||||
if (length > 4064) {
|
throw new SydApiException(0);
|
||||||
throw new SydApiException(0);
|
}
|
||||||
}
|
if (length > 4064) {
|
||||||
if (0 == sourceWrap.array().length) {
|
throw new SydApiException(0);
|
||||||
if (length < 16) {
|
}
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
if (0 == sourceWrap.array().length) {
|
||||||
bufferResult.put(sourceWrap);
|
if (length < 16) {
|
||||||
bufferResult.put(pcData);
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
||||||
sourceWrap = bufferResult;
|
bufferResult.put(sourceWrap);
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
bufferResult.put(pcData);
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, 0, pcProcData);
|
sourceWrap = bufferResult;
|
||||||
pcProcData = stringStringLongDataReturn.getProcData();
|
if (null == this.pcMac || "".equals(this.pcMac)) {
|
||||||
} else {
|
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, 0, pcProcData);
|
||||||
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, 0, pcProcData, pcMac);
|
pcProcData = stringStringLongDataReturn.getProcData();
|
||||||
pcProcData = stringBooleanLongDataReturn.getProcData();
|
} else {
|
||||||
return this;
|
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, 0, pcProcData, pcMac);
|
||||||
|
pcProcData = stringBooleanLongDataReturn.getProcData();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (length % 16 != 0) {
|
||||||
if (length % 16 != 0) {
|
ByteBuffer buffer = ByteBuffer.wrap(pcData);
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(pcData);
|
int remainder = length % 16;
|
||||||
int remainder = length % 16;
|
int intercept = length - remainder;
|
||||||
int intercept = length - remainder;
|
byte[] bytes = new byte[intercept];
|
||||||
byte[] bytes = new byte[intercept];
|
ByteBuffer byteBuffer = buffer.get(bytes, 0, intercept);
|
||||||
ByteBuffer byteBuffer = buffer.get(bytes, 0, intercept);
|
byte[] bytes1 = new byte[remainder];
|
||||||
byte[] bytes1 = new byte[remainder];
|
byteBuffer.get(bytes1);
|
||||||
byteBuffer.get(bytes1);
|
this.pcdataResult = bytes;
|
||||||
this.pcdataResult = bytes;
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + remainder);
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + remainder);
|
bufferResult.put(bytes1);
|
||||||
bufferResult.put(bytes1);
|
sourceWrap = bufferResult;
|
||||||
sourceWrap = bufferResult;
|
|
||||||
}
|
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData);
|
|
||||||
pcProcData = stringStringLongDataReturn.getProcData();
|
|
||||||
iPkgNum = 2;
|
|
||||||
} else {
|
|
||||||
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData, pcMac);
|
|
||||||
pcProcData = stringBooleanLongDataReturn.getProcData();
|
|
||||||
iPkgNum = 2;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (16 > pcData.length + sourceWrap.array().length) {
|
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
|
||||||
bufferResult.put(sourceWrap);
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
sourceWrap = bufferResult;
|
|
||||||
} else if ((pcData.length + sourceWrap.array().length) % 16 == 0) {
|
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
|
||||||
bufferResult.put(sourceWrap);
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, bytes, iPkgNum, pcProcData);
|
|
||||||
pcProcData = stringStringLongDataReturn.getProcData();
|
|
||||||
iPkgNum = 2;
|
|
||||||
} else {
|
|
||||||
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, bytes, iPkgNum, pcProcData, pcMac);
|
|
||||||
pcProcData = stringBooleanLongDataReturn.getProcData();
|
|
||||||
iPkgNum = 2;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
|
||||||
bufferResult.put(sourceWrap);
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
|
||||||
int remainder = bytes.length % 16;
|
|
||||||
int intercept = bytes.length - remainder;
|
|
||||||
byte[] pcdataByte = new byte[intercept];
|
|
||||||
ByteBuffer byteBuffer = buffer.get(pcdataByte, 0, intercept);
|
|
||||||
byte[] bytes1 = new byte[remainder];
|
|
||||||
byteBuffer.get(bytes1);
|
|
||||||
this.pcdataResult = pcdataByte;
|
|
||||||
ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
|
|
||||||
bufferResults.put(bytes1);
|
|
||||||
sourceWrap = bufferResults;
|
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
if (null == this.pcMac || "".equals(this.pcMac)) {
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData);
|
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData);
|
||||||
pcProcData = stringStringLongDataReturn.getProcData();
|
pcProcData = stringStringLongDataReturn.getProcData();
|
||||||
@ -122,18 +76,68 @@ public class SydSM4Mac {
|
|||||||
pcProcData = stringBooleanLongDataReturn.getProcData();
|
pcProcData = stringBooleanLongDataReturn.getProcData();
|
||||||
iPkgNum = 2;
|
iPkgNum = 2;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (16 > pcData.length + sourceWrap.array().length) {
|
||||||
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
||||||
|
bufferResult.put(sourceWrap);
|
||||||
|
bufferResult.put(pcData);
|
||||||
|
sourceWrap = bufferResult;
|
||||||
|
} else if ((pcData.length + sourceWrap.array().length) % 16 == 0) {
|
||||||
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
||||||
|
bufferResult.put(sourceWrap);
|
||||||
|
bufferResult.put(pcData);
|
||||||
|
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
||||||
|
if (null == this.pcMac || "".equals(this.pcMac)) {
|
||||||
|
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, bytes, iPkgNum, pcProcData);
|
||||||
|
pcProcData = stringStringLongDataReturn.getProcData();
|
||||||
|
iPkgNum = 2;
|
||||||
|
} else {
|
||||||
|
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, bytes, iPkgNum, pcProcData, pcMac);
|
||||||
|
pcProcData = stringBooleanLongDataReturn.getProcData();
|
||||||
|
iPkgNum = 2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
||||||
|
bufferResult.put(sourceWrap);
|
||||||
|
bufferResult.put(pcData);
|
||||||
|
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
||||||
|
int remainder = bytes.length % 16;
|
||||||
|
int intercept = bytes.length - remainder;
|
||||||
|
byte[] pcdataByte = new byte[intercept];
|
||||||
|
ByteBuffer byteBuffer = buffer.get(pcdataByte, 0, intercept);
|
||||||
|
byte[] bytes1 = new byte[remainder];
|
||||||
|
byteBuffer.get(bytes1);
|
||||||
|
this.pcdataResult = pcdataByte;
|
||||||
|
ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
|
||||||
|
bufferResults.put(bytes1);
|
||||||
|
sourceWrap = bufferResults;
|
||||||
|
if (null == this.pcMac || "".equals(this.pcMac)) {
|
||||||
|
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData);
|
||||||
|
pcProcData = stringStringLongDataReturn.getProcData();
|
||||||
|
iPkgNum = 2;
|
||||||
|
} else {
|
||||||
|
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData, pcMac);
|
||||||
|
pcProcData = stringBooleanLongDataReturn.getProcData();
|
||||||
|
iPkgNum = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
|
}catch ( Exception e ) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LongDataReturn disget() {
|
public LongDataReturn disget() {
|
||||||
|
|
||||||
if (is_finished) {
|
if (isFinished) {
|
||||||
throw new SydApiException(0);
|
throw new SydApiException(0);
|
||||||
}
|
}
|
||||||
this.is_finished = true;
|
this.isFinished = true;
|
||||||
if (1 == this.iPkgNum) {
|
if (1 == this.iPkgNum) {
|
||||||
this.iPkgNum = 0;
|
this.iPkgNum = 0;
|
||||||
} else if (2 == this.iPkgNum) {
|
} else if (2 == this.iPkgNum) {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import org.junit.Assert;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class LongDataTest {
|
public class LongDataTest {
|
||||||
@ -13,6 +14,8 @@ public class LongDataTest {
|
|||||||
private SydApi api;
|
private SydApi api;
|
||||||
@Before
|
@Before
|
||||||
public void init(){
|
public void init(){
|
||||||
|
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||||
|
|
||||||
SydApiBuilder builder = new SydApiBuilder(
|
SydApiBuilder builder = new SydApiBuilder(
|
||||||
new String[]{ "192.168.0.200" },
|
new String[]{ "192.168.0.200" },
|
||||||
new int[]{ 8889 },
|
new int[]{ 8889 },
|
||||||
@ -24,7 +27,7 @@ public class LongDataTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case1(){
|
public void sm3_case1(){
|
||||||
SydApiSM3 sm3 = api.initSM3();
|
SydApiSM3 sm3 = api.initSM3();
|
||||||
sm3.update(null);
|
sm3.update(null);
|
||||||
String mac = sm3.digest();
|
String mac = sm3.digest();
|
||||||
@ -32,30 +35,49 @@ public class LongDataTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case2(){
|
public void sm3_case2(){
|
||||||
SydApiSM3 sm3 = api.initSM3();
|
SydApiSM3 sm3 = api.initSM3();
|
||||||
|
sm3.update(Util.hexString2Bytes("1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"));
|
||||||
|
String mac = sm3.digest();
|
||||||
|
Assert.assertEquals("9431C865C84B02C8A7C503F53A6D6C3C66704F8F713D124610314E31B19937F7", mac);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i =0 ; i < 1000; i ++) {
|
@Test
|
||||||
|
public void sm3_case3(){
|
||||||
|
SydApiSM3 sm3 = api.initSM3();
|
||||||
|
sm3.update(Util.hexString2Bytes("1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"));
|
||||||
|
sm3.update(Util.hexString2Bytes("1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"));
|
||||||
|
String mac = sm3.digest();
|
||||||
|
Assert.assertEquals("2A217F11AD8D113EDCFED070A217DB9328FD00BFF31BA0843E04375C9F0C5B6A", mac);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sm3_case4(){
|
||||||
|
SydApiSM3 sm3 = api.initSM3();
|
||||||
|
System.out.print( "org=");
|
||||||
|
for (int i =0 ; i < 100; i ++) {
|
||||||
int lucky = new Random().nextInt(4065);
|
int lucky = new Random().nextInt(4065);
|
||||||
byte[] data = new byte[lucky];
|
byte[] data = new byte[lucky];
|
||||||
new Random().nextBytes( data );
|
new Random().nextBytes( data );
|
||||||
|
System.out.print( Util.bytes2HexString(data) );
|
||||||
sm3.update(data);
|
sm3.update(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
String mac = sm3.digest();
|
String mac = sm3.digest();
|
||||||
|
System.out.println();
|
||||||
System.out.println( mac );
|
System.out.println( mac );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case3(){
|
public void sm3_case5(){
|
||||||
SydApiSM3 sm3 = api.initSM3();
|
SydApiSM3 sm3 = api.initSM3();
|
||||||
String mac = sm3.digest();
|
String mac = sm3.digest();
|
||||||
Assert.assertEquals("1AB21D8355CFA17F8E61194831E81A8F22BEC8C728FEFB747ED035EB5082AA2B", mac);
|
Assert.assertEquals("1AB21D8355CFA17F8E61194831E81A8F22BEC8C728FEFB747ED035EB5082AA2B", mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case9(){
|
public void sm4mac_case1(){
|
||||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||||
sydApiMac.update(null);
|
sydApiMac.update(null);
|
||||||
String mac = (String) sydApiMac.disget().getData();
|
String mac = (String) sydApiMac.disget().getData();
|
||||||
@ -63,17 +85,17 @@ public class LongDataTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case10(){
|
public void sm4mac_case2(){
|
||||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||||
String mac = (String) sydApiMac.disget().getData();
|
String mac = (String) sydApiMac.disget().getData();
|
||||||
Assert.assertEquals("FF49F76AD3A71651FE1A8A9F0D2A689E", mac);
|
Assert.assertEquals("FF49F76AD3A71651FE1A8A9F0D2A689E", mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case11(){
|
public void sm4mac_case3(){
|
||||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||||
|
|
||||||
for (int i =0 ; i < 1000; i ++) {
|
for (int i =0 ; i < 10; i ++) {
|
||||||
int lucky = new Random().nextInt(4065);
|
int lucky = new Random().nextInt(4065);
|
||||||
byte[] data = new byte[lucky];
|
byte[] data = new byte[lucky];
|
||||||
System.out.println("len="+lucky);
|
System.out.println("len="+lucky);
|
||||||
@ -86,6 +108,9 @@ public class LongDataTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case5(){
|
public void case5(){
|
||||||
SydApiSM4 sydApiSM4 = api.initSM4(api, 1,1);
|
SydApiSM4 sydApiSM4 = api.initSM4(api, 1,1);
|
||||||
@ -98,7 +123,7 @@ public class LongDataTest {
|
|||||||
public void case6(){
|
public void case6(){
|
||||||
SydApiSM4 sydApiSM4 = api.initSM4(api, 1,1);
|
SydApiSM4 sydApiSM4 = api.initSM4(api, 1,1);
|
||||||
|
|
||||||
for (int i =0 ; i < 1000; i ++) {
|
for (int i =0 ; i < 10; i ++) {
|
||||||
int lucky = new Random().nextInt(4065);
|
int lucky = new Random().nextInt(4065);
|
||||||
byte[] data = new byte[lucky];
|
byte[] data = new byte[lucky];
|
||||||
System.out.println("len="+lucky);
|
System.out.println("len="+lucky);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user