修复问题
This commit is contained in:
parent
c6d6a200cc
commit
0724e374e9
@ -1,10 +1,9 @@
|
|||||||
package com.sunyard.sge.database;
|
package com.sunyard.sge.database;
|
||||||
|
|
||||||
import com.sunyard.SydApiException;
|
import com.sunyard.SydApiException;
|
||||||
|
import com.sunyard.sge.bytes.BytesQueue;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
|
|
||||||
public class SydSM4Mac {
|
public class SydSM4Mac {
|
||||||
private SydApi api;
|
private SydApi api;
|
||||||
@ -15,7 +14,8 @@ public class SydSM4Mac {
|
|||||||
private boolean is_finished;
|
private boolean is_finished;
|
||||||
private String pcMac;
|
private String pcMac;
|
||||||
private byte[] pcdataResult = new byte[0];
|
private byte[] pcdataResult = new byte[0];
|
||||||
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
|
private String pcdataStr;
|
||||||
|
BytesQueue queue = new BytesQueue();
|
||||||
|
|
||||||
public SydSM4Mac(SydApi api, int iKeyIndex) {
|
public SydSM4Mac(SydApi api, int iKeyIndex) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
@ -28,45 +28,32 @@ public class SydSM4Mac {
|
|||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SydSM4Mac update(byte[] pcData) {
|
public void update(byte[] pcData) {
|
||||||
if (null == pcData || 0 == pcData.length) {
|
if (null == pcData || 0 == pcData.length) {
|
||||||
return this;
|
return;
|
||||||
}
|
}
|
||||||
int length = pcData.length;
|
int length = pcData.length;
|
||||||
this.pcdataResult = pcData;
|
this.pcdataResult = pcData;
|
||||||
if (is_finished) {
|
if (is_finished) {
|
||||||
throw new SydApiException(0);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
if (length > 4064) {
|
if (length > 4064) {
|
||||||
throw new SydApiException(0);
|
throw new SydApiException(-1);
|
||||||
}
|
}
|
||||||
if (0 == sourceWrap.array().length) {
|
if (0 == queue.getLength()) {
|
||||||
if (length < 16) {
|
if (length < 16) {
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
queue.push(pcData);
|
||||||
bufferResult.put(sourceWrap);
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
sourceWrap = bufferResult;
|
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, 0, pcProcData);
|
|
||||||
pcProcData = stringStringLongDataReturn.getProcData();
|
|
||||||
} else {
|
|
||||||
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, 0, pcProcData, pcMac);
|
|
||||||
pcProcData = stringBooleanLongDataReturn.getProcData();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (length % 16 != 0) {
|
if (length % 16 != 0) {
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(pcData);
|
|
||||||
int remainder = length % 16;
|
int remainder = length % 16;
|
||||||
int intercept = length - remainder;
|
int intercept = length - remainder;
|
||||||
byte[] bytes = new byte[intercept];
|
byte[] result = new byte[intercept];
|
||||||
ByteBuffer byteBuffer = buffer.get(bytes, 0, intercept);
|
byte[] result2 = new byte[remainder];
|
||||||
byte[] bytes1 = new byte[remainder];
|
System.arraycopy(pcData,0,result,0,intercept);
|
||||||
byteBuffer.get(bytes1);
|
System.arraycopy(pcData,intercept,result,0,remainder);
|
||||||
this.pcdataResult = bytes;
|
queue.push(result2);
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + remainder);
|
pcdataResult=result;
|
||||||
bufferResult.put(bytes1);
|
|
||||||
sourceWrap = bufferResult;
|
|
||||||
}
|
}
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
if (null == this.pcMac || "".equals(this.pcMac)) {
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData);
|
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData);
|
||||||
@ -78,55 +65,24 @@ public class SydSM4Mac {
|
|||||||
iPkgNum = 2;
|
iPkgNum = 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (16 > (pcData.length + sourceWrap.array().length)) {
|
if (16 > (pcData.length + queue.getLength())) {
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + pcData.length);
|
queue.push(pcData);
|
||||||
bufferResult.put(sourceWrap.array());
|
|
||||||
bufferResult.put(pcData);
|
|
||||||
sourceWrap = bufferResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (16<=(pcData.length + sourceWrap.array().length)&&(pcData.length + sourceWrap.array().length) % 16 == 0) {
|
queue.push(pcData);
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + pcData.length);
|
byte[] pop = queue.pop(16, 0);
|
||||||
bufferResult.put(sourceWrap.array());
|
if (null == this.pcMac || "".equals(this.pcMac)) {
|
||||||
bufferResult.put(pcData);
|
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pop, iPkgNum, pcProcData);
|
||||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
pcProcData = stringStringLongDataReturn.getProcData();
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
iPkgNum = 2;
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, bytes, iPkgNum, pcProcData);
|
|
||||||
pcProcData = stringStringLongDataReturn.getProcData();
|
|
||||||
iPkgNum = 2;
|
|
||||||
} else {
|
|
||||||
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, bytes, iPkgNum, pcProcData, pcMac);
|
|
||||||
pcProcData = stringBooleanLongDataReturn.getProcData();
|
|
||||||
iPkgNum = 2;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + length);
|
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pop, iPkgNum, pcProcData, pcMac);
|
||||||
bufferResult.put(sourceWrap.array());
|
pcProcData = stringBooleanLongDataReturn.getProcData();
|
||||||
bufferResult.put(pcData);
|
iPkgNum = 2;
|
||||||
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
|
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
|
||||||
int remainder = bytes.length % 16;
|
|
||||||
int intercept = bytes.length - remainder;
|
|
||||||
byte[] pcdataByte = new byte[intercept];
|
|
||||||
ByteBuffer byteBuffer = buffer.get(pcdataByte, 0, intercept);
|
|
||||||
byte[] bytes1 = new byte[remainder];
|
|
||||||
byteBuffer.get(bytes1);
|
|
||||||
this.pcdataResult = pcdataByte;
|
|
||||||
ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
|
|
||||||
bufferResults.put(bytes1);
|
|
||||||
sourceWrap = bufferResults;
|
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData);
|
|
||||||
pcProcData = stringStringLongDataReturn.getProcData();
|
|
||||||
iPkgNum = 2;
|
|
||||||
} else {
|
|
||||||
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pcdataResult, iPkgNum, pcProcData, pcMac);
|
|
||||||
pcProcData = stringBooleanLongDataReturn.getProcData();
|
|
||||||
iPkgNum = 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
public LongDataReturn disget() {
|
public LongDataReturn disget() {
|
||||||
|
|
||||||
@ -139,16 +95,18 @@ public class SydSM4Mac {
|
|||||||
} else if (2 == this.iPkgNum) {
|
} else if (2 == this.iPkgNum) {
|
||||||
this.iPkgNum = 3;
|
this.iPkgNum = 3;
|
||||||
}
|
}
|
||||||
|
byte[] pop = queue.pop();
|
||||||
|
|
||||||
if (null == this.pcMac || "".equals(this.pcMac)) {
|
if (null == this.pcMac || "".equals(this.pcMac)) {
|
||||||
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, this.sourceWrap.array(), iPkgNum, pcProcData);
|
LongDataReturn<String, String> stringStringLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pop, iPkgNum, pcProcData);
|
||||||
return stringStringLongDataReturn;
|
return stringStringLongDataReturn;
|
||||||
} else {
|
} else {
|
||||||
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, this.sourceWrap.array(), iPkgNum, pcProcData, pcMac);
|
LongDataReturn<String, Boolean> stringBooleanLongDataReturn = api.SYD_SM4Mac_LongData(iKeyIndex, pop, iPkgNum, pcProcData, pcMac);
|
||||||
return stringBooleanLongDataReturn;
|
return stringBooleanLongDataReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static byte[] bytebuffer2ByteArray(ByteBuffer buffer) {
|
public static byte[] bytebuffer2ByteArray(ByteBuffer buffer) {
|
||||||
//重置 limit 和postion 值
|
//重置 limit 和postion 值
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user