整理
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
|
@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
|
@Override
|
||||||
public SydSM4Mac initSydSM4Mac(SydApi sydApi, int iKeyIndex,int ende, int key,String pcMac) {
|
public SydSM4Mac initSM4Mac(int iKeyIndex) {
|
||||||
return new SydSM4Mac(sydApi,iKeyIndex,1,null,pcMac);
|
return new SydSM4Mac(this, iKeyIndex);
|
||||||
}
|
|
||||||
|
|
||||||
public SydSM4Mac initSydSM4Mac(SydApi sydApi){
|
|
||||||
|
|
||||||
return new SydSM4Mac(sydApi);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package com.sunyard.sge.database;
|
package com.sunyard.sge.database;
|
||||||
|
|
||||||
import com.sunyard.SydApiException;
|
import com.sunyard.SydApiException;
|
||||||
import com.sunyard.sge.EntityCache;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SydApiSM4 {
|
public class SydApiSM4 {
|
||||||
|
|
||||||
@@ -15,18 +11,13 @@ public class SydApiSM4 {
|
|||||||
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;
|
||||||
private int key;
|
|
||||||
private int endeFlag;
|
|
||||||
private boolean is_finished = false;
|
private boolean is_finished = false;
|
||||||
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
||||||
|
|
||||||
|
|
||||||
|
public SydApiSM4(SydApi api, int iKeyIndex, int endeFlag) {
|
||||||
public SydApiSM4(SydApi api,int iKeyIndex, int key, int endeFlag,int iFlag) {
|
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.key = key;
|
this.iFlag = endeFlag;
|
||||||
this.endeFlag = endeFlag;
|
|
||||||
this.iFlag = iFlag;
|
|
||||||
this.iKeyIndex = iKeyIndex;
|
this.iKeyIndex = iKeyIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +72,7 @@ public class SydApiSM4 {
|
|||||||
bufferResult.put(pcData);
|
bufferResult.put(pcData);
|
||||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
||||||
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);
|
||||||
@@ -119,6 +109,7 @@ public class SydApiSM4 {
|
|||||||
// sourceWrap = null;
|
// sourceWrap = null;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer bufferResult(int plength, byte[] pcData) {
|
public ByteBuffer bufferResult(int plength, byte[] pcData) {
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
||||||
bufferResult.put(sourceWrap);
|
bufferResult.put(sourceWrap);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.sunyard.SydApiException;
|
|||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
|
||||||
public class SydSM4Mac {
|
public class SydSM4Mac {
|
||||||
private SydApi api;
|
private SydApi api;
|
||||||
@@ -16,7 +17,7 @@ public class SydSM4Mac {
|
|||||||
private byte[] pcdataResult = new byte[0];
|
private byte[] pcdataResult = new byte[0];
|
||||||
ByteBuffer sourceWrap = ByteBuffer.wrap(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.api = api;
|
||||||
this.iKeyIndex = iKeyIndex;
|
this.iKeyIndex = iKeyIndex;
|
||||||
this.pcProcData = pcProcData;
|
this.pcProcData = pcProcData;
|
||||||
@@ -126,7 +127,9 @@ public class SydSM4Mac {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public LongDataReturn disget() {
|
public LongDataReturn disget() {
|
||||||
|
|
||||||
if (is_finished) {
|
if (is_finished) {
|
||||||
throw new SydApiException(0);
|
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;
|
//package test;
|
||||||
|
//
|
||||||
import com.sunyard.proto.Util;
|
//import com.sunyard.sge.database.*;
|
||||||
import com.sunyard.sge.database.*;
|
//import org.junit.Test;
|
||||||
import org.junit.Test;
|
//
|
||||||
|
//import java.util.Random;
|
||||||
import java.nio.ByteBuffer;
|
//
|
||||||
import java.util.Random;
|
//public class test {
|
||||||
|
// private SydApi api;
|
||||||
public class test {
|
//
|
||||||
private SydApi api;
|
// @Test
|
||||||
|
// public void test01(){
|
||||||
@Test
|
// SydApiBuilder builder = new SydApiBuilder(
|
||||||
public void test01(){
|
// new String[]{ "192.168.0.200" },
|
||||||
SydApiBuilder builder = new SydApiBuilder(
|
// new int[]{ 8889 },
|
||||||
new String[]{ "192.168.0.200" },
|
// 10,
|
||||||
new int[]{ 8889 },
|
// 15
|
||||||
10,
|
// );
|
||||||
15
|
// Random random = new Random();
|
||||||
);
|
// int i = random.nextInt(4065);
|
||||||
Random random = new Random();
|
// System.out.println(i);
|
||||||
int i = random.nextInt(4065);
|
// api = builder.build();
|
||||||
System.out.println(i);
|
// SydApiSM3 sydApiSM3 = api.initSM3(api,1, 1);
|
||||||
api = builder.build();
|
// SydSM4Mac sydApiMac = api.initSM4Mac(api, 1, 1);
|
||||||
SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
// SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 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();
|
||||||
* SM4Mac updata传0-4064随机长度
|
// * int i = random.nextInt(4065);
|
||||||
* Random random = new Random();
|
// * SydSM4Mac sydApiMac = api.initSydSM4Mac(api, 1, 1,1);
|
||||||
* int i = random.nextInt(4065);
|
// * sydApiMac.update(new byte[i]);
|
||||||
* SydSM4Mac sydApiMac = api.initSydSM4Mac(api, 1, 1,1);
|
// * System.out.println(sydApiMac.disget().getData());
|
||||||
* sydApiMac.update(new byte[i]);
|
// *
|
||||||
* System.out.println(sydApiMac.disget().getData());
|
// * SM4 updata传0-4064随机长度
|
||||||
*
|
// * Random random = new Random();
|
||||||
* SM4 updata传0-4064随机长度
|
// * int i = random.nextInt(4065);
|
||||||
* Random random = new Random();
|
// * SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
||||||
* int i = random.nextInt(4065);
|
// * sydApiSM4.update(new byte[i]);
|
||||||
* SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
// * System.out.println(Util.bytes2HexString(sydApiSM4.finish()));
|
||||||
* sydApiSM4.update(new byte[i]);
|
// *
|
||||||
* System.out.println(Util.bytes2HexString(sydApiSM4.finish()));
|
// * SM3 updata传0-4064随机长度
|
||||||
*
|
// * Random random = new Random();
|
||||||
* SM3 updata传0-4064随机长度
|
// * int i = random.nextInt(4065);
|
||||||
* Random random = new Random();
|
// * SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
* int i = random.nextInt(4065);
|
// * sydApiSM3.update(new byte[i]);
|
||||||
* SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
// * System.out.println(sydApiSM3.digest());
|
||||||
* sydApiSM3.update(new byte[i]);
|
// *
|
||||||
* System.out.println(sydApiSM3.digest());
|
// * updata直接传空
|
||||||
*
|
// * SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
* updata直接传空
|
// * SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
||||||
* SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
// * SydSM4Mac sydApiMac = api.initSydSM4Mac(api, 1, 1,1);
|
||||||
* SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
// * sydApiSM3.update(null);
|
||||||
* SydSM4Mac sydApiMac = api.initSydSM4Mac(api, 1, 1,1);
|
// * sydApiSM4.update(null);
|
||||||
* sydApiSM3.update(null);
|
// * sydApiMac.update(null);
|
||||||
* sydApiSM4.update(null);
|
// *
|
||||||
* sydApiMac.update(null);
|
// * SM3直接调用digest
|
||||||
*
|
// * SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
* SM3直接调用digest
|
// * String digest = sydApiSM3.digest();
|
||||||
* SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
// * System.out.println(digest);
|
||||||
* String digest = sydApiSM3.digest();
|
// *
|
||||||
* System.out.println(digest);
|
// * SM4直接调用finish
|
||||||
*
|
// SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
||||||
* SM4直接调用finish
|
// byte[] finish = sydApiSM4.finish();
|
||||||
SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1, 1);
|
// String s = Util.bytes2HexString(finish);
|
||||||
byte[] finish = sydApiSM4.finish();
|
// System.out.print( s);
|
||||||
String s = Util.bytes2HexString(finish);
|
//
|
||||||
System.out.print( s);
|
// SM4Mac直接调用disget
|
||||||
|
// SydSM4Mac sydSM4Mac = api.initSydSM4Mac(api, 1, 1,1);
|
||||||
SM4Mac直接调用disget
|
// LongDataReturn disget = sydSM4Mac.disget();
|
||||||
SydSM4Mac sydSM4Mac = api.initSydSM4Mac(api, 1, 1,1);
|
// System.out.println(disget.getData());
|
||||||
LongDataReturn disget = sydSM4Mac.disget();
|
// **/
|
||||||
System.out.println(disget.getData());
|
//
|
||||||
**/
|
//// SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1);
|
||||||
|
//// sydApiSM4.update(new byte[4064]);
|
||||||
// SydApiSM4 sydApiSM4 = api.initSydApiSM4(api, 1,1, 1);
|
//// SydSM4Mac update = api.initSydSM4Mac(api, 1, 2).update(new byte[]{1,2,3,4,5,6,7,8,9,10,11,12});
|
||||||
// sydApiSM4.update(new byte[4064]);
|
//// System.out.println(update);
|
||||||
// SydSM4Mac update = api.initSydSM4Mac(api, 1, 2).update(new byte[]{1,2,3,4,5,6,7,8,9,10,11,12});
|
//// SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
||||||
// System.out.println(update);
|
//// sydApiSM3.update(new byte[12],0,null);
|
||||||
// SydApiSM3 sydApiSM3 = api.initSydApiSM3(api,1, 1);
|
////// SydApiSM4 sydApiSM4 = api.initSydApiSM4(1, 1);
|
||||||
// sydApiSM3.update(new byte[12],0,null);
|
//// for (int i = 0; i <2 ; i++) {
|
||||||
//// SydApiSM4 sydApiSM4 = api.initSydApiSM4(1, 1);
|
//// if (i==0){
|
||||||
// for (int i = 0; i <2 ; i++) {
|
//// sydApiSM4.update(1,new byte[21],1,1);
|
||||||
// if (i==0){
|
//// }
|
||||||
// sydApiSM4.update(1,new byte[21],1,1);
|
//// if (i==1){
|
||||||
// }
|
//// sydApiSM4.update(1,new byte[7],1,1);
|
||||||
// if (i==1){
|
//// }
|
||||||
// sydApiSM4.update(1,new byte[7],1,1);
|
//// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user