增加init/update/digest/finish长数据操作
This commit is contained in:
parent
09aabbf158
commit
7844c61bd0
@ -272,7 +272,7 @@ public interface SydApi {
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
public SydApiSM4 initSydApiSM4(SydApi sydApi,int iFlag,int ende, int key);
|
public SydApiSM4 initSydApiSM4(SydApi sydApi,int iKeyIndex,int iFlag,int ende, int key);
|
||||||
|
|
||||||
public SydApiSM3 initSydApiSM3(SydApi sydApi,int ende, int key);
|
public SydApiSM3 initSydApiSM3(SydApi sydApi,int ende, int key);
|
||||||
|
|
||||||
|
|||||||
@ -768,9 +768,9 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SydApiSM4 initSydApiSM4(SydApi sydApi,int iFlag,int ende, int key) {
|
public SydApiSM4 initSydApiSM4(SydApi sydApi,int iKeyIndex,int iFlag,int ende, int key) {
|
||||||
|
|
||||||
return new SydApiSM4(sydApi,iFlag,ende,key);
|
return new SydApiSM4(sydApi,iKeyIndex,iFlag,ende,key);
|
||||||
}
|
}
|
||||||
public SydApiSM3 initSydApiSM3(SydApi sydApi,int ende, int key) {
|
public SydApiSM3 initSydApiSM3(SydApi sydApi,int ende, int key) {
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
public class SydApiSM4 {
|
public class SydApiSM4 {
|
||||||
|
|
||||||
private SydApi api;
|
private SydApi api;
|
||||||
private int iKeyIndex=1;
|
private int iKeyIndex;
|
||||||
private byte[] pcdataResult = new byte[0];
|
private byte[] pcdataResult = new byte[0];
|
||||||
private int iPkgNum = 1;
|
private int iPkgNum = 1;
|
||||||
private int iFlag;
|
private int iFlag;
|
||||||
@ -22,11 +22,12 @@ public class SydApiSM4 {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public SydApiSM4(SydApi api, int key, int endeFlag,int iFlag) {
|
public SydApiSM4(SydApi api,int iKeyIndex, int key, int endeFlag,int iFlag) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.endeFlag = endeFlag;
|
this.endeFlag = endeFlag;
|
||||||
this.iFlag = iFlag;
|
this.iFlag = iFlag;
|
||||||
|
this.iKeyIndex = iKeyIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(byte[] pcData) {
|
public void update(byte[] pcData) {
|
||||||
@ -65,7 +66,7 @@ public class SydApiSM4 {
|
|||||||
bufferResult.put(bytes1);
|
bufferResult.put(bytes1);
|
||||||
sourceWrap = bufferResult;
|
sourceWrap = bufferResult;
|
||||||
}
|
}
|
||||||
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcData, iPkgNum, iFlag);
|
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
||||||
iKeyIndex = 2;
|
iKeyIndex = 2;
|
||||||
} else {
|
} else {
|
||||||
if (16 > pcData.length + sourceWrap.array().length) {
|
if (16 > pcData.length + sourceWrap.array().length) {
|
||||||
|
|||||||
@ -27,6 +27,9 @@ public class SydSM4Mac {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SydSM4Mac update(byte[] pcData) {
|
public SydSM4Mac update(byte[] pcData) {
|
||||||
|
if (null==pcData||0 == pcData.length) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
int length = pcData.length;
|
int length = pcData.length;
|
||||||
this.pcdataResult = pcData;
|
this.pcdataResult = pcData;
|
||||||
if (is_finished) {
|
if (is_finished) {
|
||||||
@ -35,9 +38,7 @@ public class SydSM4Mac {
|
|||||||
if (length > 4064) {
|
if (length > 4064) {
|
||||||
throw new SydApiException(0);
|
throw new SydApiException(0);
|
||||||
}
|
}
|
||||||
if (0 == length) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
if (length < 16) {
|
if (length < 16) {
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
||||||
bufferResult.put(sourceWrap);
|
bufferResult.put(sourceWrap);
|
||||||
|
|||||||
94
src/test/java/test/test.java
Normal file
94
src/test/java/test/test.java
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import com.sunyard.proto.Util;
|
||||||
|
import com.sunyard.sge.database.*;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class test {
|
||||||
|
private SydApi api;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test01(){
|
||||||
|
SydApiBuilder builder = new SydApiBuilder(
|
||||||
|
new String[]{ "192.168.0.200" },
|
||||||
|
new int[]{ 8889 },
|
||||||
|
10,
|
||||||
|
15
|
||||||
|
);
|
||||||
|
Random random = new Random();
|
||||||
|
int i = random.nextInt(4065);
|
||||||
|
System.out.println(i);
|
||||||
|
api = builder.build();
|
||||||
|
SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
|
SydSM4Mac sydApiMac = api.initSydSM4Mac(api, 1, 1,1);
|
||||||
|
SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SM4Mac updata传0-4064随机长度
|
||||||
|
* Random random = new Random();
|
||||||
|
* int i = random.nextInt(4065);
|
||||||
|
* SydSM4Mac sydApiMac = api.initSydSM4Mac(api, 1, 1,1);
|
||||||
|
* sydApiMac.update(new byte[i]);
|
||||||
|
* System.out.println(sydApiMac.disget().getData());
|
||||||
|
*
|
||||||
|
* SM4 updata传0-4064随机长度
|
||||||
|
* Random random = new Random();
|
||||||
|
* int i = random.nextInt(4065);
|
||||||
|
* SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
||||||
|
* sydApiSM4.update(new byte[i]);
|
||||||
|
* System.out.println(Util.bytes2HexString(sydApiSM4.finish()));
|
||||||
|
*
|
||||||
|
* SM3 updata传0-4064随机长度
|
||||||
|
* Random random = new Random();
|
||||||
|
* int i = random.nextInt(4065);
|
||||||
|
* SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
|
* sydApiSM3.update(new byte[i]);
|
||||||
|
* System.out.println(sydApiSM3.digest());
|
||||||
|
*
|
||||||
|
* updata直接传空
|
||||||
|
* SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
|
* SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
||||||
|
* SydSM4Mac sydApiMac = api.initSydSM4Mac(api, 1, 1,1);
|
||||||
|
* sydApiSM3.update(null);
|
||||||
|
* sydApiSM4.update(null);
|
||||||
|
* sydApiMac.update(null);
|
||||||
|
*
|
||||||
|
* SM3直接调用digest
|
||||||
|
* SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
|
* String digest = sydApiSM3.digest();
|
||||||
|
* System.out.println(digest);
|
||||||
|
*
|
||||||
|
* SM4直接调用finish
|
||||||
|
SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
||||||
|
byte[] finish = sydApiSM4.finish();
|
||||||
|
String s = Util.bytes2HexString(finish);
|
||||||
|
System.out.print( s);
|
||||||
|
|
||||||
|
SM4Mac直接调用disget
|
||||||
|
SydSM4Mac sydSM4Mac = api.initSydSM4Mac(api, 1, 1,1);
|
||||||
|
LongDataReturn disget = sydSM4Mac.disget();
|
||||||
|
System.out.println(disget.getData());
|
||||||
|
**/
|
||||||
|
|
||||||
|
// SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1);
|
||||||
|
// sydApiSM4.update(new byte[4064]);
|
||||||
|
// SydSM4Mac update = api.initSydSM4Mac(api, 1, 2).update(new byte[]{1,2,3,4,5,6,7,8,9,10,11,12});
|
||||||
|
// System.out.println(update);
|
||||||
|
// SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
|
// sydApiSM3.update(new byte[12],0,null);
|
||||||
|
//// SydApiSM4 sydApiSM4 = api.initSydApiSM4(1, 1);
|
||||||
|
// for (int i = 0; i <2 ; i++) {
|
||||||
|
// if (i==0){
|
||||||
|
// sydApiSM4.update(1,new byte[21],1,1);
|
||||||
|
// }
|
||||||
|
// if (i==1){
|
||||||
|
// sydApiSM4.update(1,new byte[7],1,1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user