8019添加返回所有信息的接口
This commit is contained in:
parent
4e42f354b5
commit
3aa8237a4d
Binary file not shown.
@ -207,6 +207,17 @@ interface SydAttachedSVApi {
|
||||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
X509 attachedVerifyAndGetX509(String sign);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return
|
||||
* 若发送报文返回证书信息标志位为0,则返回已签名数据,
|
||||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
RetWrap attachedVerifyAndGetAll(String sign);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -9980,45 +9980,11 @@ public class SydApi4j implements SydApi {
|
||||
|
||||
@Override
|
||||
public String attachedVerifyRD(String sign) {
|
||||
Proto8019 proto = new Proto8019();
|
||||
RetWrap retWrap = attachedVerifyAndGetAll(sign);
|
||||
if (retWrap == null)
|
||||
return null;
|
||||
|
||||
// 填充数据
|
||||
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("signData", sign.getBytes());
|
||||
data.put("flag$option", 1);
|
||||
|
||||
// 渲染发送
|
||||
ByteBuffer bb = proto.rend(packet);
|
||||
|
||||
synchronized (this) {
|
||||
// 响应解析
|
||||
bb = syncRead(syncSend(bb));
|
||||
}
|
||||
|
||||
Packet p = proto.parse(bb, packet);
|
||||
Map<String, Object> ret = p.toMap();
|
||||
|
||||
if (
|
||||
!Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes())
|
||||
) {
|
||||
throw new SydApiException("包序号不匹配", -4);
|
||||
}
|
||||
ret = (Map<String, Object>) ret.get("data");
|
||||
PacketSection error = (PacketSection) ret.get("error");
|
||||
byte[] be = error.getBytes();
|
||||
if ((0 != (be[0] ^ be[1]))) {
|
||||
throw new SydApiException(error.getInfo(), error.autoInt());
|
||||
}
|
||||
|
||||
PacketSection info = (PacketSection) ret.get("oData");
|
||||
byte[] oData = info.getBytes();
|
||||
|
||||
return new String(oData);
|
||||
return (String) retWrap.get("oData");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -10030,6 +9996,14 @@ public class SydApi4j implements SydApi {
|
||||
* 返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
public X509 attachedVerifyAndGetX509(String sign) {
|
||||
RetWrap retWrap = attachedVerifyAndGetAll(sign);
|
||||
if (retWrap == null)
|
||||
return null;
|
||||
|
||||
return (X509) retWrap.get("x509");
|
||||
}
|
||||
|
||||
public RetWrap attachedVerifyAndGetAll(String sign) {
|
||||
Proto8019 proto = new Proto8019();
|
||||
|
||||
// 填充数据
|
||||
@ -10073,7 +10047,15 @@ public class SydApi4j implements SydApi {
|
||||
certInfo = certInfo.substring(index);
|
||||
// System.out.println("证书信息: " + certInfo);
|
||||
X509 x509 = GetX509CertInfo(certInfo);
|
||||
return x509;
|
||||
|
||||
PacketSection oData = (PacketSection) ret.get("oData");
|
||||
byte[] oDataB = oData.getBytes();
|
||||
|
||||
RetWrap retWrap = new RetWrap();
|
||||
retWrap.put("x509", x509);
|
||||
retWrap.put("oData", new String(oDataB));
|
||||
|
||||
return retWrap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2386,7 +2386,7 @@ public class TestAllMethods {
|
||||
// 测试通过
|
||||
// 8018
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyC() {
|
||||
public void testAttachedSignAndVerifyRD() {
|
||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
@ -2400,7 +2400,7 @@ public class TestAllMethods {
|
||||
// 测试通过
|
||||
// 8018
|
||||
@Test
|
||||
public void testAttachedSignAndVerify3() {
|
||||
public void testAttachedSignAndVerifyGetX509() {
|
||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
@ -2411,6 +2411,22 @@ public class TestAllMethods {
|
||||
System.out.println("验签结果: " + verify);
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 8018
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetAll() {
|
||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509)verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
}
|
||||
|
||||
// 00883030303030303030
|
||||
// 3938
|
||||
// 30313232
|
||||
|
||||
@ -102,6 +102,20 @@ public class TestHT {
|
||||
System.out.println("验签结果: " + verify);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttachedSignAndVerifyGetAll() {
|
||||
String dn = "C=CN,O=Sunyard,OU=8001,CN=8001";
|
||||
String orgData = "111111213323143243243";
|
||||
String sign = api.attachedSign(orgData.getBytes(), dn);
|
||||
System.out.println("签名结果: " + sign);
|
||||
|
||||
RetWrap verify = api.attachedVerifyAndGetAll(sign);
|
||||
if (verify != null) {
|
||||
System.out.println("x509公钥: " + Util.bytes2HexString(((X509)verify.get("x509")).getPubKey()));
|
||||
System.out.println("签名原数据: " + verify.get("oData"));
|
||||
}
|
||||
}
|
||||
|
||||
// 测试通过
|
||||
// 76
|
||||
@Test
|
||||
|
||||
Loading…
Reference in New Issue
Block a user