接口文档更新
This commit is contained in:
@@ -13,13 +13,14 @@ import java.util.Random;
|
||||
public class LongDataTest {
|
||||
|
||||
private SydApi api;
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
public void init() {
|
||||
// System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
SydApiBuilder builder = new SydApiBuilder(
|
||||
new String[]{ "192.168.1.128" },
|
||||
new int[]{ 8889 },
|
||||
new String[]{"192.168.1.128"},
|
||||
new int[]{8889},
|
||||
10,
|
||||
15
|
||||
|
||||
@@ -28,7 +29,7 @@ public class LongDataTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm3_case1(){
|
||||
public void sm3_case1() {
|
||||
SydApiSM3 sm3 = api.initSM3();
|
||||
sm3.update(null);
|
||||
String mac = sm3.digest();
|
||||
@@ -36,7 +37,7 @@ public class LongDataTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm3_case2(){
|
||||
public void sm3_case2() {
|
||||
SydApiSM3 sm3 = api.initSM3();
|
||||
sm3.update(Util.hexString2Bytes("1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"));
|
||||
String mac = sm3.digest();
|
||||
@@ -44,7 +45,7 @@ public class LongDataTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm3_case3(){
|
||||
public void sm3_case3() {
|
||||
SydApiSM3 sm3 = api.initSM3();
|
||||
sm3.update(Util.hexString2Bytes("1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"));
|
||||
sm3.update(Util.hexString2Bytes("1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"));
|
||||
@@ -53,32 +54,32 @@ public class LongDataTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm3_case4(){
|
||||
public void sm3_case4() {
|
||||
SydApiSM3 sm3 = api.initSM3();
|
||||
System.out.print( "org=");
|
||||
for (int i =0 ; i < 100; i ++) {
|
||||
System.out.print("org=");
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int lucky = new Random().nextInt(4065);
|
||||
byte[] data = new byte[lucky];
|
||||
new Random().nextBytes( data );
|
||||
System.out.print( Util.bytes2HexString(data) );
|
||||
new Random().nextBytes(data);
|
||||
System.out.print(Util.bytes2HexString(data));
|
||||
sm3.update(data);
|
||||
}
|
||||
|
||||
String mac = sm3.digest();
|
||||
System.out.println();
|
||||
System.out.println( mac );
|
||||
System.out.println(mac);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sm3_case5(){
|
||||
public void sm3_case5() {
|
||||
SydApiSM3 sm3 = api.initSM3();
|
||||
String mac = sm3.digest();
|
||||
Assert.assertEquals("1AB21D8355CFA17F8E61194831E81A8F22BEC8C728FEFB747ED035EB5082AA2B", mac);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm4mac_case1(){
|
||||
public void sm4mac_case1() {
|
||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||
sydApiMac.update(null);
|
||||
String mac = (String) sydApiMac.disget().getData();
|
||||
@@ -86,123 +87,103 @@ public class LongDataTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm4mac_case2(){
|
||||
public void sm4mac_case2() {
|
||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||
String mac = (String) sydApiMac.disget().getData();
|
||||
Assert.assertEquals("FF49F76AD3A71651FE1A8A9F0D2A689E", mac);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sm4mac_case3(){
|
||||
public void sm4mac_case3() {
|
||||
SydSM4Mac sydApiMac = api.initSM4Mac(1);
|
||||
|
||||
for (int i =0 ; i < 10; i ++) {
|
||||
int lucky = new Random().nextInt(4065);
|
||||
byte[] data = new byte[lucky];
|
||||
System.out.println("len="+lucky);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// int lucky = new Random().nextInt(4065);
|
||||
byte[] data = new byte[66];
|
||||
// System.out.println("len=" + lucky);
|
||||
// new Random().nextBytes( data );
|
||||
// sydApiMac.setPcMac("405C2DCF4884240B7F2E4FF56B00639A");
|
||||
sydApiMac.setPcMac("72A7EFF0004CE7D2A1B7C2260726EC38");
|
||||
sydApiMac.update(data);
|
||||
}
|
||||
|
||||
String mac = (String) sydApiMac.disget().getData();
|
||||
System.out.println( mac );
|
||||
boolean mac = (boolean) sydApiMac.disget().getData();
|
||||
// String mac1 = (String) sydApiMac.disget().getData();
|
||||
System.out.println(mac);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void case5(){
|
||||
SydApiSM4 sydApiSM4 = api.initSM4(1,1);
|
||||
public void case5() {
|
||||
SydApiSM423 sydApiSM4 = api.initSM4(1, 1);
|
||||
byte[] enData = sydApiSM4.finish();
|
||||
System.out.println(Util.bytes2HexString( enData ) );
|
||||
Assert.assertArrayEquals( Util.hexString2Bytes("FF49F76AD3A71651FE1A8A9F0D2A689E"), enData );
|
||||
System.out.println(Util.bytes2HexString(enData));
|
||||
Assert.assertArrayEquals(Util.hexString2Bytes("FF49F76AD3A71651FE1A8A9F0D2A689E"), enData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case6(){
|
||||
SydApiSM4 sydApiSM4 = api.initSM4(1,1);
|
||||
public void case6() {
|
||||
SydApiSM423 sydApiSM4 = api.initSM4(1, 1);
|
||||
|
||||
for (int i =0 ; i < 10; i ++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int lucky = new Random().nextInt(4065);
|
||||
byte[] data = new byte[lucky];
|
||||
System.out.println("len="+lucky);
|
||||
System.out.println("len=" + lucky);
|
||||
|
||||
new Random().nextBytes( data );
|
||||
new Random().nextBytes(data);
|
||||
sydApiSM4.update(data);
|
||||
}
|
||||
|
||||
byte[] enData = sydApiSM4.finish();
|
||||
System.out.println(Util.bytes2HexString( enData ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case12(){
|
||||
for (int i =0 ; i < 1000; i ++) {
|
||||
int lucky = new Random().nextInt(4065);
|
||||
SydApiSM4 sydApiSM4 = api.initSM4( 1,1);
|
||||
// byte[] inData = new byte[lucky];
|
||||
// byte[] update = sydApiSM4.update(new byte[89]);
|
||||
// byte[] enData = sydApiSM4.finish();
|
||||
// ByteBuffer buffer = ByteBuffer.allocate(inData.length+enData.length);
|
||||
// buffer.put(update);
|
||||
// buffer.put(enData);
|
||||
|
||||
SydApiSM4 sydApiSM42 = api.initSM4(1,0);
|
||||
sydApiSM42.update(new byte[80]);
|
||||
byte[] deData = sydApiSM42.finish();
|
||||
|
||||
// Assert.assertArrayEquals( deData , inData);
|
||||
}
|
||||
System.out.println(Util.bytes2HexString(enData));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void sm4(){
|
||||
public void sm4() {
|
||||
|
||||
int max = 1;
|
||||
int max = 1000;
|
||||
int size = 4065;
|
||||
SydApiSM4 en = api.initSM4( 1,1);
|
||||
SydApiSM4 de = api.initSM4(1,0);
|
||||
SydApiSM423 en = api.initSM4(1, 1);
|
||||
SydApiSM423 de = api.initSM4(1, 0);
|
||||
|
||||
ByteBuffer inData = ByteBuffer.allocate( max * size );
|
||||
ByteBuffer enData = ByteBuffer.allocate( max * size + 16);
|
||||
ByteBuffer deData = ByteBuffer.allocate( max * size );
|
||||
ByteBuffer inData = ByteBuffer.allocate(max * size);
|
||||
ByteBuffer enData = ByteBuffer.allocate(max * size + 16);
|
||||
ByteBuffer deData = ByteBuffer.allocate(max * size);
|
||||
|
||||
|
||||
|
||||
for (int i =0 ; i < max; i ++) {
|
||||
for (int i = 0; i < max; i++) {
|
||||
int lucky = new Random().nextInt(size);
|
||||
byte[] data = new byte[lucky];
|
||||
inData.put( data );
|
||||
System.out.println( "in=" + data.length );
|
||||
enData.put( en.update(data) );
|
||||
inData.put(data);
|
||||
System.out.println("in=" + data.length);
|
||||
enData.put(en.update(data));
|
||||
}
|
||||
byte[] v = en.finish();
|
||||
System.out.println("finish=" + v.length );
|
||||
enData.put( v );
|
||||
System.out.println("finish=" + v.length);
|
||||
enData.put(v);
|
||||
|
||||
System.out.println("原文=" + inData.position() );
|
||||
System.out.println("密文=" + enData.position() );
|
||||
System.out.println("原文=" + inData.position());
|
||||
System.out.println("密文=" + enData.position());
|
||||
|
||||
if ( 1 == max ) {
|
||||
if (1 == max) {
|
||||
|
||||
byte[] in = new byte[ inData.position() ];
|
||||
System.arraycopy( inData.array(), 0, in, 0, in.length );
|
||||
byte[] in = new byte[inData.position()];
|
||||
System.arraycopy(inData.array(), 0, in, 0, in.length);
|
||||
|
||||
byte[] bytes = api.SYD_SM4_ShortData(1, in , Consts.ECB_ENC);
|
||||
System.out.println("对比 =" + Util.bytes2HexString(bytes) );
|
||||
byte[] bytes = api.SYD_SM4_ShortData(1, in, Consts.ECB_ENC);
|
||||
System.out.println("对比 =" + Util.bytes2HexString(bytes));
|
||||
|
||||
|
||||
byte[] look = new byte[ enData.position() ];
|
||||
System.arraycopy( enData.array(), 0, look, 0, look.length );
|
||||
System.out.println( Util.bytes2HexString( look ) );
|
||||
byte[] look = new byte[enData.position()];
|
||||
System.arraycopy(enData.array(), 0, look, 0, look.length);
|
||||
System.out.println(Util.bytes2HexString(look));
|
||||
|
||||
System.out.println("eq=" + Arrays.equals( look, bytes ));
|
||||
System.out.println("eq=" + Arrays.equals(look, bytes));
|
||||
|
||||
|
||||
byte[] deBytes = api.SYD_SM4_ShortData(1, bytes , Consts.ECB_DEC );
|
||||
System.out.println("还原=" + Util.bytes2HexString(deBytes) );
|
||||
byte[] deBytes = api.SYD_SM4_ShortData(1, bytes, Consts.ECB_DEC);
|
||||
System.out.println("还原=" + Util.bytes2HexString(deBytes));
|
||||
|
||||
}
|
||||
|
||||
@@ -211,44 +192,27 @@ public class LongDataTest {
|
||||
|
||||
|
||||
byte[] data = new byte[16];
|
||||
enData.get( data );
|
||||
deData.put( de.update(data) );
|
||||
while (true){
|
||||
enData.get(data);
|
||||
deData.put(de.update(data));
|
||||
while (true) {
|
||||
int lucky = new Random().nextInt(size);
|
||||
System.out.println( "lucky=" + lucky );
|
||||
System.out.println("lucky=" + lucky);
|
||||
data = new byte[lucky];
|
||||
|
||||
if ( enData.position() + lucky >= enData.limit() ) {
|
||||
if (enData.position() + lucky >= enData.limit()) {
|
||||
// 到头了
|
||||
data = new byte[enData.limit() - enData.position()];
|
||||
enData.get( data );
|
||||
deData.put( de.update(data) );
|
||||
deData.put( de.finish() );
|
||||
enData.get(data);
|
||||
deData.put(de.update(data));
|
||||
deData.put(de.finish());
|
||||
break;
|
||||
} else {
|
||||
enData.get( data );
|
||||
deData.put( de.update(data) );
|
||||
enData.get(data);
|
||||
deData.put(de.update(data));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Assert.assertArrayEquals( deData.array() , inData.array());
|
||||
Assert.assertArrayEquals(deData.array(), inData.array());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void case11(){
|
||||
SydApiSM4 sydApiSM4 = api.initSM4(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 );
|
||||
byte[] update = sydApiSM4.update(data);
|
||||
|
||||
|
||||
byte[] enData = sydApiSM4.finish();
|
||||
System.out.println(Util.bytes2HexString( enData ) );
|
||||
}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user