check修改
This commit is contained in:
parent
f9ab152cf1
commit
a43d1269d0
@ -105,6 +105,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
if (isShortLinkMode) {
|
if (isShortLinkMode) {
|
||||||
SYD_Disconnect();
|
SYD_Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 配合链接池,不再需要释放。
|
// 配合链接池,不再需要释放。
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,13 +178,29 @@ 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;
|
||||||
}
|
}
|
||||||
|
if (isShortLinkMode) {
|
||||||
|
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 {
|
||||||
|
return new LongDataReturn<String, String>(Util.bytes2HexString(hash), null);
|
||||||
|
}
|
||||||
|
} catch (SydApiException e) {
|
||||||
|
le = e;
|
||||||
|
if (e.getRetCode() < 0) {
|
||||||
|
log.error("HA 重试");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
synchronized (api) {
|
||||||
try {
|
try {
|
||||||
byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum);
|
byte[] hash = api.SYD_SM3_LongData(pcData, procData, iPkgNum);
|
||||||
log.debug("api.SYD_SM3_LongData方法返回值:{}", Arrays.toString(hash));
|
log.debug("api.SYD_SM3_LongData方法返回值:{}", Arrays.toString(hash));
|
||||||
@ -202,11 +219,6 @@ public class SydApi4Database implements SydApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
|
||||||
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
lockableObject.unlock();
|
|
||||||
}
|
}
|
||||||
throw le;
|
throw le;
|
||||||
}
|
}
|
||||||
@ -230,6 +242,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
if (null == api) {
|
if (null == api) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isShortLinkMode) {
|
||||||
try {
|
try {
|
||||||
if (Consts.ECB_ENC == iFlag) {
|
if (Consts.ECB_ENC == iFlag) {
|
||||||
return api.SYMEncryptData(
|
return api.SYMEncryptData(
|
||||||
@ -252,6 +265,32 @@ public class SydApi4Database implements SydApi {
|
|||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
synchronized (api) {
|
||||||
|
try {
|
||||||
|
if (Consts.ECB_ENC == iFlag) {
|
||||||
|
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 le;
|
throw le;
|
||||||
}
|
}
|
||||||
@ -283,6 +322,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
if (null == api) {
|
if (null == api) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isShortLinkMode) {
|
||||||
try {
|
try {
|
||||||
if (Consts.ECB_ENC == iFlag) {
|
if (Consts.ECB_ENC == iFlag) {
|
||||||
return api.SYMEncryptDecryptBatchData(8, 1, null, keys, 1, pcData);
|
return api.SYMEncryptDecryptBatchData(8, 1, null, keys, 1, pcData);
|
||||||
@ -298,6 +338,25 @@ public class SydApi4Database implements SydApi {
|
|||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
synchronized (api) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
} catch (SydApiException e) {
|
||||||
|
le = e;
|
||||||
|
if (e.getRetCode() < 0) {
|
||||||
|
log.error("HA 重试");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw le;
|
throw le;
|
||||||
}
|
}
|
||||||
@ -321,6 +380,34 @@ public class SydApi4Database implements SydApi {
|
|||||||
if (null == api) {
|
if (null == api) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isShortLinkMode) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
synchronized (api) {
|
||||||
try {
|
try {
|
||||||
if (Consts.ECB_ENC == iFlag) {
|
if (Consts.ECB_ENC == iFlag) {
|
||||||
return api.SYD_SM4_LongData(
|
return api.SYD_SM4_LongData(
|
||||||
@ -347,6 +434,8 @@ public class SydApi4Database implements SydApi {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
throw le;
|
throw le;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,6 +458,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
if (null == api) {
|
if (null == api) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isShortLinkMode) {
|
||||||
try {
|
try {
|
||||||
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
|
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
|
||||||
String[] ret = new String[list.size()];
|
String[] ret = new String[list.size()];
|
||||||
@ -388,6 +478,29 @@ public class SydApi4Database implements SydApi {
|
|||||||
}
|
}
|
||||||
throw e;
|
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 le;
|
throw le;
|
||||||
}
|
}
|
||||||
@ -411,6 +524,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
if (null == api) {
|
if (null == api) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isShortLinkMode) {
|
||||||
try {
|
try {
|
||||||
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
|
List<byte[]> list = api.SYMEncryptDecryptBatchData(8, 2, null, keys, 1, pcData);
|
||||||
boolean[] ret = new boolean[list.size()];
|
boolean[] ret = new boolean[list.size()];
|
||||||
@ -430,6 +544,29 @@ public class SydApi4Database implements SydApi {
|
|||||||
}
|
}
|
||||||
throw e;
|
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 le;
|
throw le;
|
||||||
}
|
}
|
||||||
@ -458,6 +595,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
if (null == api) {
|
if (null == api) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isShortLinkMode) {
|
||||||
try {
|
try {
|
||||||
byte[] ret = api.SYD_SM4_LongData(
|
byte[] ret = api.SYD_SM4_LongData(
|
||||||
8,
|
8,
|
||||||
@ -485,6 +623,37 @@ public class SydApi4Database implements SydApi {
|
|||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
synchronized (api) {
|
||||||
|
try {
|
||||||
|
byte[] ret = api.SYD_SM4_LongData(
|
||||||
|
8,
|
||||||
|
2, iv,
|
||||||
|
"SK" + SYMUtil.genPrivateKeyMark("000000", "00A", keyIndex),
|
||||||
|
1,
|
||||||
|
pcData, iPkgNum);
|
||||||
|
|
||||||
|
byte[] mac = new byte[16];
|
||||||
|
System.arraycopy(ret, ret.length - 16, mac, 0, 16);
|
||||||
|
|
||||||
|
// 仅一包 和 尾包 返回最终结果
|
||||||
|
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 le;
|
throw le;
|
||||||
}
|
}
|
||||||
@ -523,6 +692,7 @@ public class SydApi4Database implements SydApi {
|
|||||||
if (null == api) {
|
if (null == api) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isShortLinkMode) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
return api.SYD_SM4Mac_ShortData(keyIndex, pcData);
|
return api.SYD_SM4Mac_ShortData(keyIndex, pcData);
|
||||||
@ -536,6 +706,23 @@ public class SydApi4Database implements SydApi {
|
|||||||
throw e;
|
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 le;
|
throw le;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user