Changes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.sunyard.sge.database;
|
||||
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.util.List;
|
||||
@@ -26,9 +26,17 @@ public interface SydApi {
|
||||
static void SYD_SetLogConfig(
|
||||
String pcLogPath,
|
||||
int iLogLevel) {
|
||||
|
||||
Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel);
|
||||
SydApi4j.setLogger( logger );
|
||||
Logger log = LogFactory.getLogger();
|
||||
try {
|
||||
if (iLogLevel<0||iLogLevel>3){
|
||||
throw new IllegalArgumentException("IllegalArgumentException");
|
||||
}
|
||||
Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel);
|
||||
SydApi4j.setLogger( logger );
|
||||
}
|
||||
catch (IllegalArgumentException e){
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,8 +288,4 @@ public interface SydApi {
|
||||
byte[] pcData,
|
||||
String pcMac
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,16 +2,19 @@ package com.sunyard.sge.database;
|
||||
|
||||
import com.sunyard.SydApiException;
|
||||
import com.sunyard.proto.Util;
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import com.sunyard.util.SYMUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 上海黄金交易所 - 数据库加密方案
|
||||
*/
|
||||
public class SydApi4Database implements SydApi {
|
||||
|
||||
Logger log = LogFactory.getLogger();
|
||||
private SydApi4j[] hsms = null;
|
||||
|
||||
@Deprecated
|
||||
@@ -24,6 +27,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public SydApi SYD_Connect_Ex(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iDealTimeOut) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_Connect_Ex方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList), Arrays.toString(iPortList), iConnectTimeOut, iDealTimeOut);
|
||||
}
|
||||
SydApi4j api = (SydApi4j) new SydApi4j().connect(pcIpList[0], iPortList[0], null, iConnectTimeOut);
|
||||
hsms = new SydApi4j[]{ api };
|
||||
return this;
|
||||
@@ -43,6 +49,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public String SYD_SM3_Hash_ShortData(byte[] pcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM3_Hash_ShortData方法接收参数:pcData:{}", Arrays.toString(pcData));
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -51,6 +60,7 @@ public class SydApi4Database implements SydApi {
|
||||
for (SydApi4j api : this.hsms) {
|
||||
try {
|
||||
byte[] hash = api.SYD_SM3_LongData(pcData, null, 0);
|
||||
log.debug("api.SYD_SM3_LongData方法返回值:{}",Arrays.toString(hash));
|
||||
return Util.bytes2HexString(hash);
|
||||
} catch (SydApiException e) {
|
||||
le = e;
|
||||
@@ -65,6 +75,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public LongDataReturn<String, String> SYD_SM3_Hash_LongData(byte[] pcData, int iPkgNum, String pcProcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM3_Hash_LongData方法接收参数:pcData:{},iPkgNum:{},pcProcData:{}", Arrays.toString(pcData), iPkgNum, pcProcData);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -72,12 +85,14 @@ public class SydApi4Database implements SydApi {
|
||||
byte[] procData = null;
|
||||
if (2 == iPkgNum || 3 == iPkgNum) {
|
||||
procData = Util.hexString2Bytes(pcProcData);
|
||||
log.debug("Util.hexString2Bytes方法返回值:{}",Arrays.toString(procData));
|
||||
|
||||
}
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
try {
|
||||
byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum);
|
||||
|
||||
log.debug("api.SYD_SM3_LongData方法返回值:{}",Arrays.toString(hash));
|
||||
if (0 == iPkgNum || 3 == iPkgNum) {
|
||||
return new LongDataReturn<String, String>(null, Util.bytes2HexString(hash));
|
||||
} else {
|
||||
@@ -96,7 +111,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public byte[] SYD_SM4_ShortData(int iKeyIndex, byte[] pcData, int iFlag) {
|
||||
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iFlag);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -132,6 +149,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public List<byte[]> SYD_SM4_BatchData(int[] iKeyIndex, List<byte[]> pcData, int iFlag) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},iFlag:{}", iKeyIndex, pcData.size(), iFlag);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -146,6 +166,7 @@ public class SydApi4Database implements SydApi {
|
||||
try {
|
||||
if (Consts.ECB_ENC == iFlag) {
|
||||
return api.SYMEncryptDecryptBatchData(8, 1, null, keys, 1, pcData);
|
||||
|
||||
} else {
|
||||
return api.SYMEncryptDecryptBatchData(9, 1, null, keys, 1, pcData);
|
||||
}
|
||||
@@ -162,6 +183,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public byte[] SYD_SM4_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, int iFlag) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, iFlag);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -200,6 +224,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public String[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4Mac_BatchData:iKeyIndex:{},pcData元素个数为:{}", iKeyIndex, pcData.size());
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -234,6 +261,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public boolean[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData, String[] pcMac) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4Mac_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},pcMac:{}", iKeyIndex, pcData.size(), Arrays.toString(pcMac));
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -245,7 +275,6 @@ public class SydApi4Database implements SydApi {
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
try {
|
||||
|
||||
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
|
||||
boolean[] ret = new boolean[list.size()];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
@@ -269,6 +298,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public LongDataReturn<String, String> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -316,7 +348,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public LongDataReturn<String, Boolean> SYD_SM4Mac_LongData(int iKeyIndex, byte[] pcData, int iPkgNum, String pcProcData, String pcMac) {
|
||||
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4Mac_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},pcProcData:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, pcProcData, pcMac);
|
||||
}
|
||||
LongDataReturn<String, String> ret = SYD_SM4Mac_LongData(iKeyIndex, pcData, iPkgNum, pcProcData);
|
||||
|
||||
// 仅一包 和 尾包 返回最终结果
|
||||
@@ -330,13 +364,15 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public String SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData) {
|
||||
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4Mac_ShortData方法接收参数:iKeyIndex:{},pcData:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData));
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
|
||||
String keyIndex = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex));
|
||||
|
||||
log.debug("\"SK\" + SYMUtil.genPrivateKeyMark方法返回值:{}",keyIndex);
|
||||
SydApiException le = null;
|
||||
for (SydApi4j api : this.hsms) {
|
||||
try {
|
||||
@@ -356,6 +392,9 @@ public class SydApi4Database implements SydApi {
|
||||
|
||||
@Override
|
||||
public boolean SYD_SM4Mac_ShortData(int iKeyIndex, byte[] pcData, String pcMac) {
|
||||
if (LogFactory.iLogLevel==3) {
|
||||
log.debug("SYD_SM4Mac_ShortData方法接收参数:{}", iKeyIndex, Arrays.toString(pcData), pcMac);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@@ -365,7 +404,7 @@ public class SydApi4Database implements SydApi {
|
||||
}
|
||||
|
||||
String mac = this.SYD_SM4Mac_ShortData(iKeyIndex, pcData);
|
||||
|
||||
log.debug(this+".SYD_SM4Mac_ShortData方法返回值:{}",mac);
|
||||
return pcMac.equals(mac);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,25 +3,24 @@ package com.sunyard.sge.database;
|
||||
import com.sunyard.sge.database.pool.HsmLinkInfo;
|
||||
import com.sunyard.sge.database.pool.SydApiPool;
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SydApiBuilder {
|
||||
|
||||
Logger log = LogFactory.getLogger();
|
||||
private SydApiPool pool;
|
||||
|
||||
public SydApiBuilder(
|
||||
String[] pcIpList,
|
||||
int[] iPortList,
|
||||
int iConnectTimeOut,
|
||||
int iDealTimeOut
|
||||
) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
log.debug("创建链接");
|
||||
|
||||
log.debug("SydApiBuilder构造方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList),Arrays.toString(iPortList),iConnectTimeOut,iDealTimeOut);
|
||||
HsmLinkInfo[] linkInfo = HsmLinkInfo.mutiHsmLinkInfo(pcIpList, iPortList, iConnectTimeOut, iDealTimeOut);
|
||||
log.debug("mutiHsmLinkInfo方法返回值:linkInfo:{}",linkInfo);
|
||||
this.pool = new SydApiPool(linkInfo);
|
||||
|
||||
warmUp( pcIpList, iPortList, iConnectTimeOut, iDealTimeOut );
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,15 @@ package com.sunyard.sge.database.pool;
|
||||
|
||||
|
||||
import com.sunyard.sge.log.LogFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* 到加密机的链接信息
|
||||
*/
|
||||
public class HsmLinkInfo {
|
||||
|
||||
private String pcIp;
|
||||
private int iPort;
|
||||
private int iConnectTimeOut;
|
||||
@@ -24,8 +26,8 @@ public class HsmLinkInfo {
|
||||
|
||||
public static HsmLinkInfo[] mutiHsmLinkInfo(String[] pcIpList, int[] iPortList, int iConnectTimeOut, int iAllDealTimeOut) {
|
||||
Logger log = LogFactory.getLogger();
|
||||
log.debug("mutiHsmLinkInfo方法接收参数:pcIpList:{},iPortList:{},iConnectTimeOut:{},iDealTimeOut:{}", Arrays.toString(pcIpList),Arrays.toString(iPortList),iConnectTimeOut,iAllDealTimeOut);
|
||||
log.debug("链接参数整理");
|
||||
|
||||
if (null == pcIpList &&
|
||||
null == iPortList &&
|
||||
pcIpList.length != iPortList.length) {
|
||||
@@ -66,4 +68,14 @@ public class HsmLinkInfo {
|
||||
public int getiDealTimeOut() {
|
||||
return iDealTimeOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HsmLinkInfo{" +
|
||||
"pcIp='" + pcIp + '\'' +
|
||||
", iPort=" + iPort +
|
||||
", iConnectTimeOut=" + iConnectTimeOut +
|
||||
", iDealTimeOut=" + iDealTimeOut +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user