完工
This commit is contained in:
@@ -1,28 +1,72 @@
|
||||
package sample;
|
||||
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.sge.database.Consts;
|
||||
import com.sunyard.sge.database.SydApi;
|
||||
import com.sunyard.sge.database.SydApi4Database;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Sample
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
|
||||
SydApi4Database.SYD_SetLogConfig("./sydapi/log", 1);
|
||||
// System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
|
||||
SydApi api = new SydApi4Database();
|
||||
try {
|
||||
api = api.SYD_Connect_Ex(
|
||||
new String[]{ "192.168.0.100" },
|
||||
new String[]{ "192.168.0.200" },
|
||||
new int[]{ 8889 },
|
||||
3,
|
||||
10,
|
||||
15
|
||||
);
|
||||
|
||||
|
||||
// 短数据
|
||||
shortData( api );
|
||||
|
||||
|
||||
// 批量
|
||||
batchData( api );
|
||||
|
||||
|
||||
} finally {
|
||||
api.SYD_Disconnect_Ex();
|
||||
if ( null != api ) {
|
||||
api.SYD_Disconnect_Ex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void shortData(SydApi api){
|
||||
// 密钥索引
|
||||
int keyIdx = 0;
|
||||
// 测试数据
|
||||
byte[] data = new byte[16];
|
||||
byte[] encData = api.SYD_SM4_ShortData( keyIdx , data, Consts.ECB_ENC );
|
||||
byte[] orgData = api.SYD_SM4_ShortData( keyIdx , encData, Consts.ECB_DEC );
|
||||
System.out.println( "HEX=" + Util.bytes2HexString( encData ) );
|
||||
Assert.assertArrayEquals( orgData, data );
|
||||
}
|
||||
|
||||
public static void batchData(SydApi api){
|
||||
// 密钥索引
|
||||
int[] keyIdx = new int[]{ 0, 1, 2 };
|
||||
// 测试数据
|
||||
List<byte[]> data = new ArrayList<>();
|
||||
data.add( new byte[8] );
|
||||
data.add( new byte[16] );
|
||||
data.add( new byte[1024] );
|
||||
|
||||
List<byte[]> encData = api.SYD_SM4_BatchData( keyIdx , data, Consts.ECB_ENC );
|
||||
List<byte[]> orgData = api.SYD_SM4_BatchData( keyIdx , encData, Consts.ECB_DEC );
|
||||
|
||||
for ( int i = 0 ; i < data.size() ; i++ ) {
|
||||
System.out.println( "HEX=" + Util.bytes2HexString( encData.get( i ) ) );
|
||||
Assert.assertArrayEquals( orgData.get( i ), data.get( i ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user