整理
This commit is contained in:
@@ -272,9 +272,9 @@ public interface SydApi {
|
||||
);
|
||||
|
||||
|
||||
public SydApiSM4 initSydApiSM4(SydApi sydApi,int iKeyIndex,int iFlag,int ende, int key);
|
||||
public SydApiSM4 initSM4(SydApi sydApi, int iKeyIndex, int ende);
|
||||
|
||||
public SydApiSM3 initSydApiSM3(SydApi sydApi,int ende, int key);
|
||||
public SydApiSM3 initSM3();
|
||||
|
||||
public SydSM4Mac initSydSM4Mac(SydApi sydApi,int iKeyIndex,int ende, int key,String pcMac);
|
||||
public SydSM4Mac initSM4Mac(int iKeyIndex);
|
||||
}
|
||||
|
||||
@@ -768,22 +768,17 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
|
||||
@Override
|
||||
public SydApiSM4 initSydApiSM4(SydApi sydApi,int iKeyIndex,int iFlag,int ende, int key) {
|
||||
public SydApiSM4 initSM4(SydApi sydApi, int iKeyIndex, int ende) {
|
||||
|
||||
return new SydApiSM4(sydApi,iKeyIndex,iFlag,ende,key);
|
||||
return new SydApiSM4(this,iKeyIndex,ende);
|
||||
}
|
||||
public SydApiSM3 initSydApiSM3(SydApi sydApi,int ende, int key) {
|
||||
public SydApiSM3 initSM3() {
|
||||
|
||||
return new SydApiSM3(sydApi);
|
||||
return new SydApiSM3(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SydSM4Mac initSydSM4Mac(SydApi sydApi, int iKeyIndex,int ende, int key,String pcMac) {
|
||||
return new SydSM4Mac(sydApi,iKeyIndex,1,null,pcMac);
|
||||
}
|
||||
|
||||
public SydSM4Mac initSydSM4Mac(SydApi sydApi){
|
||||
|
||||
return new SydSM4Mac(sydApi);
|
||||
public SydSM4Mac initSM4Mac(int iKeyIndex) {
|
||||
return new SydSM4Mac(this, iKeyIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.sunyard.sge.database;
|
||||
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.sge.EntityCache;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SydApiSM4 {
|
||||
|
||||
@@ -15,18 +11,13 @@ public class SydApiSM4 {
|
||||
private byte[] pcdataResult = new byte[0];
|
||||
private int iPkgNum = 1;
|
||||
private int iFlag;
|
||||
private int key;
|
||||
private int endeFlag;
|
||||
private boolean is_finished = false;
|
||||
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
||||
|
||||
|
||||
|
||||
public SydApiSM4(SydApi api,int iKeyIndex, int key, int endeFlag,int iFlag) {
|
||||
public SydApiSM4(SydApi api, int iKeyIndex, int endeFlag) {
|
||||
this.api = api;
|
||||
this.key = key;
|
||||
this.endeFlag = endeFlag;
|
||||
this.iFlag = iFlag;
|
||||
this.iFlag = endeFlag;
|
||||
this.iKeyIndex = iKeyIndex;
|
||||
}
|
||||
|
||||
@@ -81,8 +72,7 @@ public class SydApiSM4 {
|
||||
bufferResult.put(pcData);
|
||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
||||
api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
||||
bufferResult.put(sourceWrap);
|
||||
bufferResult.put(pcData);
|
||||
@@ -119,6 +109,7 @@ public class SydApiSM4 {
|
||||
// sourceWrap = null;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public ByteBuffer bufferResult(int plength, byte[] pcData) {
|
||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
||||
bufferResult.put(sourceWrap);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.sunyard.SydApiException;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
public class SydSM4Mac {
|
||||
private SydApi api;
|
||||
@@ -16,7 +17,7 @@ public class SydSM4Mac {
|
||||
private byte[] pcdataResult = new byte[0];
|
||||
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
||||
|
||||
public SydSM4Mac(SydApi api, int iKeyIndex, int iPkgNum, String pcProcData,String pcMac) {
|
||||
public SydSM4Mac(SydApi api, int iKeyIndex) {
|
||||
this.api = api;
|
||||
this.iKeyIndex = iKeyIndex;
|
||||
this.pcProcData = pcProcData;
|
||||
@@ -126,7 +127,9 @@ public class SydSM4Mac {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public LongDataReturn disget() {
|
||||
|
||||
if (is_finished) {
|
||||
throw new SydApiException(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package test;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.sge.database.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class LongDataTest {
|
||||
|
||||
private SydApi api;
|
||||
@Before
|
||||
public void init(){
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
new String[]{ "192.168.0.200" },
|
||||
new int[]{ 8889 },
|
||||
10,
|
||||
15
|
||||
|
||||
);
|
||||
api = builder.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case1(){
|
||||
SydApiSM3 sm3 = api.initSM3();
|
||||
sm3.update(null);
|
||||
String mac = sm3.digest();
|
||||
Assert.assertEquals("1AB21D8355CFA17F8E61194831E81A8F22BEC8C728FEFB747ED035EB5082AA2B", mac);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case2(){
|
||||
SydApiSM3 sm3 = api.initSM3();
|
||||
|
||||
for (int i =0 ; i < 1000; i ++) {
|
||||
int lucky = new Random().nextInt(4065);
|
||||
byte[] data = new byte[lucky];
|
||||
new Random().nextBytes( data );
|
||||
sm3.update(data);
|
||||
}
|
||||
|
||||
String mac = sm3.digest();
|
||||
System.out.println( mac );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void case3(){
|
||||
SydApiSM3 sm3 = api.initSM3();
|
||||
String mac = sm3.digest();
|
||||
Assert.assertEquals("1AB21D8355CFA17F8E61194831E81A8F22BEC8C728FEFB747ED035EB5082AA2B", mac);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case9(){
|
||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||
sydApiMac.update(null);
|
||||
String mac = (String) sydApiMac.disget().getData();
|
||||
Assert.assertEquals("FF49F76AD3A71651FE1A8A9F0D2A689E", mac);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case10(){
|
||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||
String mac = (String) sydApiMac.disget().getData();
|
||||
Assert.assertEquals("FF49F76AD3A71651FE1A8A9F0D2A689E", mac);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case11(){
|
||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||
|
||||
for (int i =0 ; i < 1000; i ++) {
|
||||
int lucky = new Random().nextInt(4065);
|
||||
byte[] data = new byte[lucky];
|
||||
System.out.println("len="+lucky);
|
||||
new Random().nextBytes( data );
|
||||
sydApiMac.update(data);
|
||||
}
|
||||
|
||||
String mac = (String) sydApiMac.disget().getData();
|
||||
System.out.println( mac );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void case5(){
|
||||
SydApiSM4 sydApiSM4 = api.initSM4(api, 1,1);
|
||||
byte[] enData = sydApiSM4.finish();
|
||||
System.out.println(Util.bytes2HexString( enData ) );
|
||||
Assert.assertArrayEquals( Util.hexString2Bytes("FF49F76AD3A71651FE1A8A9F0D2A689E"), enData );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case6(){
|
||||
SydApiSM4 sydApiSM4 = api.initSM4(api, 1,1);
|
||||
|
||||
for (int i =0 ; i < 1000; i ++) {
|
||||
int lucky = new Random().nextInt(4065);
|
||||
byte[] data = new byte[lucky];
|
||||
System.out.println("len="+lucky);
|
||||
|
||||
new Random().nextBytes( data );
|
||||
sydApiSM4.update(data);
|
||||
}
|
||||
|
||||
byte[] enData = sydApiSM4.finish();
|
||||
System.out.println(Util.bytes2HexString( enData ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,94 +1,92 @@
|
||||
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);
|
||||
//package test;
|
||||
//
|
||||
//import com.sunyard.sge.database.*;
|
||||
//import org.junit.Test;
|
||||
//
|
||||
//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.initSM3(api,1, 1);
|
||||
// SydSM4Mac sydApiMac = api.initSM4Mac(api, 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);
|
||||
//// }
|
||||
//// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user