MAC 长度

This commit is contained in:
cheney 2022-05-26 14:59:34 +08:00
parent 6d587f37d1
commit 784d44e3de
6 changed files with 26 additions and 44 deletions

View File

@ -172,10 +172,10 @@
}
function retMacLen(){
if ( 0 == $packet.data.mode$option ) {
return 16;
if ( 2 == $packet.data.mode$option ) {
return 32;
} else {
return 16;
return 16;
}
}

View File

@ -57,6 +57,12 @@ public class SydApiException extends RuntimeException{
case 129:
this.msg = "没有该指令";
break;
case 0x8006 : {
this.msg = "输入的数据格式错误";
break;
}
case 32770:
this.msg = "签名验证错误(P7) ";
break;

View File

@ -54,6 +54,8 @@ public interface SydCertApi {
int nKeyTypes
);
public String SM2GetPrivateKeyC(String privateKeyTag);
String SM2GetPublicKeyC_QX(
int userId,
int nKeyTypes

View File

@ -74,7 +74,6 @@ interface SydHashApi {
public void MACCheck(int alg, int keyType, String AK, int fullMode, byte[] infoData, String mac);
public String calcPBOCMAC(int mode, int keyType, String key, byte[] data, int block, byte[] iv);
}

View File

@ -59,7 +59,7 @@ interface SydAttachedSVApi {
* @return 签名结果
*/
String SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData);
String SM2SignC(int flag, String pUserID, String privateKey, byte[] publicKey, byte[] orgData);
/**
* SM2 私钥签名
* @param pUserID 使用者的 ID最大长度为 16 位数字右对齐

View File

@ -464,7 +464,8 @@ public class SydApi4j implements SydApi {
PacketSection error = (PacketSection) ret.get("error");
byte[] be = error.getBytes();
if ((0 != (be[0] ^ be[1]))) {
SydApiException e = new SydApiException(error.getInfo(), error.autoInt());
println("验签失败=" + e.toString() );
return false;
}
return true;
@ -711,6 +712,8 @@ public class SydApi4j implements SydApi {
PacketSection error = (PacketSection) ret.get("error");
byte[] be = error.getBytes();
if ((0 != (be[0] ^ be[1]))) {
SydApiException e = new SydApiException(error.getInfo(), error.autoInt());
println("验签失败=" + e.toString() );
return false;
}
@ -3475,9 +3478,12 @@ public class SydApi4j implements SydApi {
* @param orgData 要签名的信息
* @return 签名结果
*/
public String SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData) {
return SM2SignC( flag, "1234567812345678", privateKey, publicKey, orgData);
}
// 测试通过
@Override
public String SM2SignC(int flag, String privateKey, byte[] publicKey, byte[] orgData) {
public String SM2SignC(int flag, String uid, String privateKey, byte[] publicKey, byte[] orgData) {
Proto74 proto = new Proto74();
@ -3489,7 +3495,7 @@ public class SydApi4j implements SydApi {
PacketSN sn = PacketSN.gen();
packet.put("header", sn.getSn().array());
data.put("signatureDataType$option", 1);
data.put("userId", "1234567812345678".getBytes());
data.put("userId", uid.getBytes());
data.put("publicKey", publicKey);
data.put("infoData", orgData);
data.put("privateKeyTag", flag == 1 ? privateKey : "999999999999999999999999999");
@ -3689,51 +3695,17 @@ public class SydApi4j implements SydApi {
return ((PacketSection) ret.get("signature")).getString();
}
@Override
public boolean SM2Verify(
int nOrgDataType,
byte[] publicKey,
byte[] orgData,
String base64Sign
) {
){
String certNo = "1234567812345678";
//ProtocolRender render = pset.getProtocolReqRender("75");
Proto75 proto = new Proto75();
byte[] sign = Util.decodeBase64(base64Sign);
// 填充数据
HashMap<String, Object> packet = new HashMap<String, Object>();
HashMap<String, Object> data = new HashMap<String, Object>();
packet.put("data", data);
PacketSN sn = PacketSN.gen();
packet.put("header", sn.getSn().array());
data.put("signatureDataType$option", nOrgDataType);
data.put("signature", sign);
data.put("userId", certNo.getBytes());
data.put("infoData", orgData);
data.put("hashData", orgData);
data.put("publicKey", publicKey);
// 渲染发送
ByteBuffer bb = proto.rend(packet);
//System.out.println(Util.bytes2HexString(Util.toArray(bb)));
synchronized (this) {
// 响应解析
bb = syncRead(syncSend(bb));
}
bb.position(12);
byte[] v = new byte[2];
bb.get(v, 0, v.length);
String a = Util.bytes2HexString(v);
if ("3030".equals(a)) {
return true;
} else {
return false;
}
return SM2Verify(certNo, nOrgDataType, publicKey, orgData, base64Sign);
}
@Override
public String SM2Sign(
int nOrgDataType,
@ -10071,6 +10043,9 @@ public class SydApi4j implements SydApi {
PacketSection error = (PacketSection) ret.get("error");
byte[] be = error.getBytes();
if ((0 != (be[0] ^ be[1]))) {
SydApiException e = new SydApiException(error.getInfo(), error.autoInt());
println("验签失败=" + e.toString() );
return false;
}