Merge remote-tracking branch 'origin/dev-1.0' into dev-1.0
# Conflicts: # src/test/java/test/LongDataTest.java
This commit is contained in:
commit
35a167bf57
@ -272,7 +272,7 @@ public interface SydApi {
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
public SydApiSM4 initSM4(SydApi sydApi, int iKeyIndex, int ende);
|
public SydApiSM4 initSM4( int iKeyIndex, int ende);
|
||||||
|
|
||||||
public SydApiSM3 initSM3();
|
public SydApiSM3 initSM3();
|
||||||
|
|
||||||
|
|||||||
@ -768,7 +768,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SydApiSM4 initSM4(SydApi sydApi, int iKeyIndex, int ende) {
|
public SydApiSM4 initSM4(int iKeyIndex, int ende) {
|
||||||
|
|
||||||
return new SydApiSM4(this,iKeyIndex,ende);
|
return new SydApiSM4(this,iKeyIndex,ende);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,10 @@ public class SydApiSM4 {
|
|||||||
this.iKeyIndex = iKeyIndex;
|
this.iKeyIndex = iKeyIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(byte[] pcData) {
|
public byte[] update(byte[] pcData) {
|
||||||
this.pcdataResult = pcData;
|
this.pcdataResult = pcData;
|
||||||
if (null == pcData || pcData.length == 0) {
|
if (null == pcData || pcData.length == 0) {
|
||||||
return;
|
return new byte[0];
|
||||||
}
|
}
|
||||||
int plength = pcData.length;
|
int plength = pcData.length;
|
||||||
if (is_finished) {
|
if (is_finished) {
|
||||||
@ -58,20 +58,22 @@ public class SydApiSM4 {
|
|||||||
bufferResult.put(bytes1);
|
bufferResult.put(bytes1);
|
||||||
sourceWrap = bufferResult;
|
sourceWrap = bufferResult;
|
||||||
}
|
}
|
||||||
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
iPkgNum = 2;
|
||||||
iPkgNum = 2;
|
return api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (16 > pcData.length + sourceWrap.array().length) {
|
if (16 > pcData.length + sourceWrap.array().length) {
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
||||||
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
|
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
|
||||||
bufferResult.put(pcData);
|
bufferResult.put(pcData);
|
||||||
sourceWrap = bufferResult;
|
sourceWrap = bufferResult;
|
||||||
|
return new byte[0];
|
||||||
} else if ((pcData.length + sourceWrap.array().length) % 16 == 0) {
|
} else if ((pcData.length + sourceWrap.array().length) % 16 == 0) {
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
|
||||||
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
|
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
|
||||||
bufferResult.put(pcData);
|
bufferResult.put(pcData);
|
||||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
||||||
api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag);
|
return 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(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
|
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
|
||||||
@ -88,8 +90,8 @@ public class SydApiSM4 {
|
|||||||
ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
|
ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
|
||||||
bufferResults.put(bytes1);
|
bufferResults.put(bytes1);
|
||||||
sourceWrap = bufferResults;
|
sourceWrap = bufferResults;
|
||||||
api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
|
||||||
iPkgNum = 2;
|
iPkgNum = 2;
|
||||||
|
return api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -99,7 +99,7 @@ public class LongDataTest {
|
|||||||
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);
|
||||||
new Random().nextBytes( data );
|
// new Random().nextBytes( data );
|
||||||
sydApiMac.update(data);
|
sydApiMac.update(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ public class LongDataTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case5(){
|
public void case5(){
|
||||||
SydApiSM4 sydApiSM4 = api.initSM4(api, 1,1);
|
SydApiSM4 sydApiSM4 = api.initSM4(1,1);
|
||||||
byte[] enData = sydApiSM4.finish();
|
byte[] enData = sydApiSM4.finish();
|
||||||
System.out.println(Util.bytes2HexString( enData ) );
|
System.out.println(Util.bytes2HexString( enData ) );
|
||||||
Assert.assertArrayEquals( Util.hexString2Bytes("FF49F76AD3A71651FE1A8A9F0D2A689E"), enData );
|
Assert.assertArrayEquals( Util.hexString2Bytes("FF49F76AD3A71651FE1A8A9F0D2A689E"), enData );
|
||||||
@ -121,7 +121,7 @@ public class LongDataTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void case6(){
|
public void case6(){
|
||||||
SydApiSM4 sydApiSM4 = api.initSM4(api, 1,1);
|
SydApiSM4 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);
|
int lucky = new Random().nextInt(4065);
|
||||||
@ -136,6 +136,22 @@ public class LongDataTest {
|
|||||||
System.out.println(Util.bytes2HexString( enData ) );
|
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[] bytes = new byte[lucky];
|
||||||
|
sydApiSM4.update(new byte[lucky]);
|
||||||
|
byte[] finish = sydApiSM4.finish();
|
||||||
|
SydApiSM4 sydApiSM42 = api.initSM4(1,0);
|
||||||
|
sydApiSM42.update(finish);
|
||||||
|
byte[] finish1 = sydApiSM42.finish();
|
||||||
|
System.out.println("原始数据:"+Arrays.toString(bytes)+",\n"+"解密后数据:"+Arrays.toString(finish1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user