完工
This commit is contained in:
parent
f79a2b69e6
commit
01880dca0d
66
kit.json
Normal file
66
kit.json
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
"vars": {
|
||||||
|
"version": "git()",
|
||||||
|
"out_path": "./pack",
|
||||||
|
"target_f1": "./target/sydapi4j-jar-with-dependencies.jar",
|
||||||
|
"target_t1": "%out_path%/sydapi4j-jar-with-dependencies.jar",
|
||||||
|
"target_f2": "./target/sydapi4j.jar",
|
||||||
|
"target_t2": "%out_path%/sydapi4j.jar"
|
||||||
|
},
|
||||||
|
"clear": [
|
||||||
|
{
|
||||||
|
"func": "rmdir",
|
||||||
|
"path": "%out_path%"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"init": [
|
||||||
|
{
|
||||||
|
"func": "mkdir",
|
||||||
|
"path": "%out_path%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "mkdir",
|
||||||
|
"path": "%out_path%/jar"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "mkdir",
|
||||||
|
"path": "%out_path%/jar/dependences"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "mkdir",
|
||||||
|
"path": "%out_path%/doc"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": [{
|
||||||
|
"func" : "pom",
|
||||||
|
"xml" : "%out_path%/jar"
|
||||||
|
}, {
|
||||||
|
"cmd" : "mvn dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=%out_path%/jar/dependences",
|
||||||
|
"check": "BUILD SUCCESS"
|
||||||
|
}],
|
||||||
|
"gen" : [{
|
||||||
|
"cmd" : "dproto"
|
||||||
|
}],
|
||||||
|
"build": [
|
||||||
|
{
|
||||||
|
"cmd": "mvn package -DskipTests",
|
||||||
|
"check": "BUILD SUCCESS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "rename",
|
||||||
|
"from": "%target_f1%",
|
||||||
|
"to": "%target_t1%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "rename",
|
||||||
|
"from": "%target_f2%",
|
||||||
|
"to": "%target_t2%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"func": "zip",
|
||||||
|
"from": "%out_path%",
|
||||||
|
"to": "%out_path%/sydapi-%version%.zip"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
7
pom.xml
7
pom.xml
@ -23,6 +23,13 @@
|
|||||||
<version>4.11</version>
|
<version>4.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sunyard</groupId>
|
||||||
|
<artifactId>sydapi4j</artifactId>
|
||||||
|
<version>1.0.20220712</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -1,30 +0,0 @@
|
|||||||
package com.sunyard;
|
|
||||||
|
|
||||||
public class SydApiException extends RuntimeException {
|
|
||||||
// 错误编码
|
|
||||||
private int retCode;
|
|
||||||
|
|
||||||
// 错误消息
|
|
||||||
private String msg;
|
|
||||||
|
|
||||||
public SydApiException(int retCode, String msg) {
|
|
||||||
this.retCode = retCode;
|
|
||||||
this.msg = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRetCode() {
|
|
||||||
return retCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMsg() {
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SydApiException{" +
|
|
||||||
"retCode=" + retCode +
|
|
||||||
", msg='" + msg + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6
src/main/java/com/sunyard/sge/database/Consts.java
Normal file
6
src/main/java/com/sunyard/sge/database/Consts.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package com.sunyard.sge.database;
|
||||||
|
|
||||||
|
public class Consts {
|
||||||
|
public static final int ECB_DEC = 0;
|
||||||
|
public static final int ECB_ENC = 1;
|
||||||
|
}
|
||||||
@ -1,5 +1,9 @@
|
|||||||
package com.sunyard.sge.database;
|
package com.sunyard.sge.database;
|
||||||
|
|
||||||
|
import com.sunyard.SydApiException;
|
||||||
|
import com.sunyard.util.SYMUtil;
|
||||||
|
import racal.sunyard.main.SydApi4j;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,28 +13,81 @@ import java.util.List;
|
|||||||
public class SydApi4Database implements SydApi
|
public class SydApi4Database implements SydApi
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void SYD_SetLogConfig (
|
// public static void SYD_SetLogConfig (
|
||||||
String pcLogPath,
|
// String pcLogPath,
|
||||||
int iLogLevel) {
|
// int iLogLevel) {
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
private SydApi4j api4j = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
||||||
return null;
|
|
||||||
|
|
||||||
|
if ( null == pcIpList &&
|
||||||
|
null == iPortList &&
|
||||||
|
pcIpList.length != iPortList.length ) {
|
||||||
|
throw new IllegalArgumentException("入参错误");
|
||||||
|
}
|
||||||
|
if ( null != api4j ) {
|
||||||
|
this.SYD_Disconnect_Ex();
|
||||||
|
}
|
||||||
|
|
||||||
|
api4j = (SydApi4j) new SydApi4j().connect( pcIpList[0], iPortList[0], null, iConnectTimeOut, iDealTimeOut);
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void SYD_Disconnect_Ex() {
|
public void SYD_Disconnect_Ex() {
|
||||||
|
if ( null != this.api4j ) {
|
||||||
|
try {
|
||||||
|
this.api4j.disconnect();
|
||||||
|
}catch ( Exception e ){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.api4j = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] SYD_SM4_ShortData(int iKeyIndex, byte[] pcData, int iFlag) {
|
public byte[] SYD_SM4_ShortData(int iKeyIndex, byte[] pcData, int iFlag) {
|
||||||
return new byte[0];
|
|
||||||
|
if ( null == this.api4j ) {
|
||||||
|
throw new SydApiException(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String keyIndex = String.format("%08d", iKeyIndex);
|
||||||
|
|
||||||
|
if ( Consts.ECB_ENC == iFlag ) {
|
||||||
|
return this.api4j.SYMEncryptData(
|
||||||
|
com.sunyard.SydApi.NALG_SM4,
|
||||||
|
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
|
||||||
|
1,
|
||||||
|
pcData );
|
||||||
|
} else {
|
||||||
|
return this.api4j.SYMDecryptData(
|
||||||
|
com.sunyard.SydApi.NALG_SM4,
|
||||||
|
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
|
||||||
|
1,
|
||||||
|
pcData );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<byte[]> SYD_SM4_BatchData(int[] iKeyIndex, List<byte[]> pcData, int iFlag) {
|
public List<byte[]> SYD_SM4_BatchData(int[] iKeyIndex, List<byte[]> pcData, int iFlag) {
|
||||||
return null;
|
if ( null == this.api4j ) {
|
||||||
|
throw new SydApiException(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] keys = new String[ iKeyIndex.length ];
|
||||||
|
for ( int i = 0 ; i < iKeyIndex.length ; i++ ) {
|
||||||
|
keys[i] = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex[i] ));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Consts.ECB_ENC == iFlag ) {
|
||||||
|
return this.api4j.SYMEncryptDecryptBatchData(8, keys, 1, pcData);
|
||||||
|
} else {
|
||||||
|
return this.api4j.SYMEncryptDecryptBatchData(9, keys, 1, pcData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,28 +1,72 @@
|
|||||||
package sample;
|
package sample;
|
||||||
|
|
||||||
|
import com.sunyard.proto.Util;
|
||||||
|
import com.sunyard.sge.database.Consts;
|
||||||
import com.sunyard.sge.database.SydApi;
|
import com.sunyard.sge.database.SydApi;
|
||||||
import com.sunyard.sge.database.SydApi4Database;
|
import com.sunyard.sge.database.SydApi4Database;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Sample
|
public class Sample
|
||||||
{
|
{
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
SydApi4Database.SYD_SetLogConfig("./sydapi/log", 1);
|
// System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||||
|
|
||||||
SydApi api = new SydApi4Database();
|
SydApi api = new SydApi4Database();
|
||||||
try {
|
try {
|
||||||
api = api.SYD_Connect_Ex(
|
api = api.SYD_Connect_Ex(
|
||||||
new String[]{ "192.168.0.100" },
|
new String[]{ "192.168.0.200" },
|
||||||
new int[]{ 8889 },
|
new int[]{ 8889 },
|
||||||
3,
|
10,
|
||||||
15
|
15
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// 短数据
|
||||||
|
shortData( api );
|
||||||
|
|
||||||
|
|
||||||
|
// 批量
|
||||||
|
batchData( api );
|
||||||
|
|
||||||
|
|
||||||
} finally {
|
} 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 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
target/classes/com/sunyard/sge/database/Consts.class
Normal file
BIN
target/classes/com/sunyard/sge/database/Consts.class
Normal file
Binary file not shown.
BIN
target/classes/com/sunyard/sge/database/SydApi.class
Normal file
BIN
target/classes/com/sunyard/sge/database/SydApi.class
Normal file
Binary file not shown.
BIN
target/classes/com/sunyard/sge/database/SydApi4Database.class
Normal file
BIN
target/classes/com/sunyard/sge/database/SydApi4Database.class
Normal file
Binary file not shown.
BIN
target/test-classes/sample/Sample.class
Normal file
BIN
target/test-classes/sample/Sample.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user