check修改

This commit is contained in:
junj2.liang 2022-08-16 11:08:14 +08:00
parent f9ab152cf1
commit a43d1269d0

View File

@ -105,6 +105,7 @@ public class SydApi4Database implements SydApi {
if (isShortLinkMode) { if (isShortLinkMode) {
SYD_Disconnect(); SYD_Disconnect();
} }
// 配合链接池不再需要释放 // 配合链接池不再需要释放
} }
@ -177,37 +178,48 @@ public class SydApi4Database implements SydApi {
} }
SydApiException le = null; SydApiException le = null;
LockableObject lockableObject = new LockableObject();
lockableObject.lock();
try {
for (SydApi4j api : this.hsms) { for (SydApi4j api : this.hsms) {
if (null == api) { if (null == api) {
continue; continue;
} }
try { if (isShortLinkMode) {
byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum); try {
log.debug("api.SYD_SM3_LongData方法返回值{}", Arrays.toString(hash)); byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum);
if (0 == iPkgNum || 3 == iPkgNum) { log.debug("api.SYD_SM3_LongData方法返回值{}", Arrays.toString(hash));
return new LongDataReturn<String, String>(null, Util.bytes2HexString(hash)); if (0 == iPkgNum || 3 == iPkgNum) {
} else { return new LongDataReturn<String, String>(null, Util.bytes2HexString(hash));
return new LongDataReturn<String, String>(Util.bytes2HexString(hash), null); } else {
return new LongDataReturn<String, String>(Util.bytes2HexString(hash), null);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
} }
} catch (SydApiException e) { } else {
le = e; synchronized (api) {
if (e.getRetCode() < 0) { try {
log.error("HA 重试"); byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum);
continue; log.debug("api.SYD_SM3_LongData方法返回值{}", Arrays.toString(hash));
if (0 == iPkgNum || 3 == iPkgNum) {
return new LongDataReturn<String, String>(null, Util.bytes2HexString(hash));
} else {
return new LongDataReturn<String, String>(Util.bytes2HexString(hash), null);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
}
} }
throw e;
} }
} }
}
catch (Exception e){
}
finally {
lockableObject.unlock();
}
throw le; throw le;
} }
@ -230,27 +242,54 @@ public class SydApi4Database implements SydApi {
if (null == api) { if (null == api) {
continue; continue;
} }
try { if (isShortLinkMode) {
if (Consts.ECB_ENC == iFlag) { try {
return api.SYMEncryptData( if (Consts.ECB_ENC == iFlag) {
com.sunyard.SydApi.NALG_SM4, return api.SYMEncryptData(
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex), com.sunyard.SydApi.NALG_SM4,
1, "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
pcData); 1,
} else { pcData);
return api.SYMDecryptData( } else {
com.sunyard.SydApi.NALG_SM4, return api.SYMDecryptData(
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex), com.sunyard.SydApi.NALG_SM4,
1, "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
pcData); 1,
pcData);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
} }
} catch (SydApiException e) { } else {
le = e; synchronized (api) {
if (e.getRetCode() < 0) { try {
log.error("HA 重试"); if (Consts.ECB_ENC == iFlag) {
continue; return api.SYMEncryptData(
com.sunyard.SydApi.NALG_SM4,
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
1,
pcData);
} else {
return api.SYMDecryptData(
com.sunyard.SydApi.NALG_SM4,
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
1,
pcData);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
}
} }
throw e;
} }
} }
throw le; throw le;
@ -283,20 +322,40 @@ public class SydApi4Database implements SydApi {
if (null == api) { if (null == api) {
continue; continue;
} }
try { if (isShortLinkMode) {
if (Consts.ECB_ENC == iFlag) { try {
return api.SYMEncryptDecryptBatchData(8, 1, null, keys, 1, pcData); if (Consts.ECB_ENC == iFlag) {
return api.SYMEncryptDecryptBatchData(8, 1, null, keys, 1, pcData);
} else { } else {
return api.SYMEncryptDecryptBatchData(9, 1, null, keys, 1, pcData); return api.SYMEncryptDecryptBatchData(9, 1, null, keys, 1, pcData);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
} }
} catch (SydApiException e) { } else {
le = e; synchronized (api) {
if (e.getRetCode() < 0) { try {
log.error("HA 重试"); if (Consts.ECB_ENC == iFlag) {
continue; return api.SYMEncryptDecryptBatchData(8, 1, null, keys, 1, pcData);
} else {
return api.SYMEncryptDecryptBatchData(9, 1, null, keys, 1, pcData);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
}
} }
throw e;
} }
} }
throw le; throw le;
@ -321,30 +380,60 @@ public class SydApi4Database implements SydApi {
if (null == api) { if (null == api) {
continue; continue;
} }
try { if (isShortLinkMode) {
if (Consts.ECB_ENC == iFlag) { try {
return api.SYD_SM4_LongData( if (Consts.ECB_ENC == iFlag) {
8, return api.SYD_SM4_LongData(
1, null, 8,
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex), 1, null,
1, "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
pcData, iPkgNum); 1,
} else { pcData, iPkgNum);
return api.SYD_SM4_LongData( } else {
9, return api.SYD_SM4_LongData(
1, null, 9,
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex), 1, null,
1, "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
pcData, iPkgNum); 1,
} pcData, iPkgNum);
}
} catch (SydApiException e) { } catch (SydApiException e) {
le = e; le = e;
if (e.getRetCode() < 0) { if (e.getRetCode() < 0) {
log.error("HA 重试"); log.error("HA 重试");
continue; continue;
}
throw e;
}
} else {
synchronized (api) {
try {
if (Consts.ECB_ENC == iFlag) {
return api.SYD_SM4_LongData(
8,
1, null,
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
1,
pcData, iPkgNum);
} else {
return api.SYD_SM4_LongData(
9,
1, null,
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
1,
pcData, iPkgNum);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
}
} }
throw e;
} }
} }
throw le; throw le;
@ -369,24 +458,48 @@ public class SydApi4Database implements SydApi {
if (null == api) { if (null == api) {
continue; continue;
} }
try { if (isShortLinkMode) {
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData); try {
String[] ret = new String[list.size()]; List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
for (int i = 0; i < list.size(); i++) { String[] ret = new String[list.size()];
byte[] mac = new byte[16]; for (int i = 0; i < list.size(); i++) {
byte[] buff = list.get(i); byte[] mac = new byte[16];
System.arraycopy(buff, buff.length - 16, mac, 0, 16); byte[] buff = list.get(i);
ret[i] = Util.bytes2HexString(buff); System.arraycopy(buff, buff.length - 16, mac, 0, 16);
} ret[i] = Util.bytes2HexString(buff);
return ret; }
return ret;
} catch (SydApiException e) { } catch (SydApiException e) {
le = e; le = e;
if (e.getRetCode() < 0) { if (e.getRetCode() < 0) {
log.error("HA 重试"); log.error("HA 重试");
continue; continue;
}
throw e;
}
} else {
synchronized (api) {
try {
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
String[] ret = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
byte[] mac = new byte[16];
byte[] buff = list.get(i);
System.arraycopy(buff, buff.length - 16, mac, 0, 16);
ret[i] = Util.bytes2HexString(buff);
}
return ret;
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
}
} }
throw e;
} }
} }
throw le; throw le;
@ -411,24 +524,48 @@ public class SydApi4Database implements SydApi {
if (null == api) { if (null == api) {
continue; continue;
} }
try { if (isShortLinkMode) {
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData); try {
boolean[] ret = new boolean[list.size()]; List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
for (int i = 0; i < list.size(); i++) { boolean[] ret = new boolean[list.size()];
byte[] mac = new byte[16]; for (int i = 0; i < list.size(); i++) {
byte[] buff = list.get(i); byte[] mac = new byte[16];
System.arraycopy(buff, buff.length - 16, mac, 0, 16); byte[] buff = list.get(i);
ret[i] = pcMac[i].equals(Util.bytes2HexString(buff)); System.arraycopy(buff, buff.length - 16, mac, 0, 16);
} ret[i] = pcMac[i].equals(Util.bytes2HexString(buff));
}
return ret; return ret;
} catch (SydApiException e) { } catch (SydApiException e) {
le = e; le = e;
if (e.getRetCode() < 0) { if (e.getRetCode() < 0) {
log.error("HA 重试"); log.error("HA 重试");
continue; continue;
}
throw e;
}
} else {
synchronized (api) {
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++) {
byte[] mac = new byte[16];
byte[] buff = list.get(i);
System.arraycopy(buff, buff.length - 16, mac, 0, 16);
ret[i] = pcMac[i].equals(Util.bytes2HexString(buff));
}
return ret;
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
}
} }
throw e;
} }
} }
throw le; throw le;
@ -458,32 +595,64 @@ public class SydApi4Database implements SydApi {
if (null == api) { if (null == api) {
continue; continue;
} }
try { if (isShortLinkMode) {
byte[] ret = api.SYD_SM4_LongData( try {
8, byte[] ret = api.SYD_SM4_LongData(
2, iv, 8,
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex), 2, iv,
1, "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
pcData, iPkgNum); 1,
pcData, iPkgNum);
byte[] mac = new byte[16]; byte[] mac = new byte[16];
System.arraycopy(ret, ret.length - 16, mac, 0, 16); System.arraycopy(ret, ret.length - 16, mac, 0, 16);
// 仅一包 尾包 返回最终结果 // 仅一包 尾包 返回最终结果
if (Consts.PkgNumAll == iPkgNum || Consts.PkgNumTail == iPkgNum) { if (Consts.PkgNumAll == iPkgNum || Consts.PkgNumTail == iPkgNum) {
return new LongDataReturn<>(null, Util.bytes2HexString(mac)); return new LongDataReturn<>(null, Util.bytes2HexString(mac));
} else { } else {
// 返回中间值 // 返回中间值
return new LongDataReturn<>(Util.bytes2HexString(mac), null); return new LongDataReturn<>(Util.bytes2HexString(mac), null);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
} }
} else {
synchronized (api) {
try {
byte[] ret = api.SYD_SM4_LongData(
8,
2, iv,
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
1,
pcData, iPkgNum);
} catch (SydApiException e) { byte[] mac = new byte[16];
le = e; System.arraycopy(ret, ret.length - 16, mac, 0, 16);
if (e.getRetCode() < 0) {
log.error("HA 重试"); // 仅一包 尾包 返回最终结果
continue; if (Consts.PkgNumAll == iPkgNum || Consts.PkgNumTail == iPkgNum) {
return new LongDataReturn<>(null, Util.bytes2HexString(mac));
} else {
// 返回中间值
return new LongDataReturn<>(Util.bytes2HexString(mac), null);
}
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
}
} }
throw e;
} }
} }
throw le; throw le;
@ -523,17 +692,35 @@ public class SydApi4Database implements SydApi {
if (null == api) { if (null == api) {
continue; continue;
} }
try { if (isShortLinkMode) {
try {
return api.SYD_SM4Mac_ShortData(keyIndex, pcData); return api.SYD_SM4Mac_ShortData(keyIndex, pcData);
} catch (SydApiException e) { } catch (SydApiException e) {
le = e; le = e;
if (e.getRetCode() < 0) { if (e.getRetCode() < 0) {
log.error("HA 重试"); log.error("HA 重试");
continue; continue;
}
throw e;
}
}
else {
synchronized (api){
try {
return api.SYD_SM4Mac_ShortData(keyIndex, pcData);
} catch (SydApiException e) {
le = e;
if (e.getRetCode() < 0) {
log.error("HA 重试");
continue;
}
throw e;
}
} }
throw e;
} }
} }
throw le; throw le;