完工
This commit is contained in:
@@ -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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.util.SYMUtil;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -9,28 +13,81 @@ import java.util.List;
|
||||
public class SydApi4Database implements SydApi
|
||||
{
|
||||
|
||||
public static void SYD_SetLogConfig (
|
||||
String pcLogPath,
|
||||
int iLogLevel) {
|
||||
}
|
||||
// public static void SYD_SetLogConfig (
|
||||
// String pcLogPath,
|
||||
// int iLogLevel) {
|
||||
// }
|
||||
|
||||
private SydApi4j api4j = null;
|
||||
|
||||
@Override
|
||||
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
|
||||
public void SYD_Disconnect_Ex() {
|
||||
|
||||
if ( null != this.api4j ) {
|
||||
try {
|
||||
this.api4j.disconnect();
|
||||
}catch ( Exception e ){
|
||||
}
|
||||
}
|
||||
this.api4j = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user