添加8018,8019两个指令所对应的接口。
This commit is contained in:
@@ -167,6 +167,28 @@ interface SydAttachedSVApi {
|
||||
byte[] orgData,
|
||||
String sign
|
||||
);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名(遵循 PKCS#7)
|
||||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制带公钥证书的数字签名(遵循 PKCS#7)。
|
||||
*
|
||||
* @param orgData 待签名数据
|
||||
* @param sCertDN 证书DN
|
||||
* @return
|
||||
* 符合PKCS7标准的签名结果
|
||||
*/
|
||||
String attachedSign(byte[] orgData, String sCertDN);
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return
|
||||
* 若发送报文返回证书信息标志位为0,则返回已签名数据,
|
||||
* 若发送报文返回证书信息标志位为1,则返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
X509 attachedVerify(String sign);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9668,6 +9668,121 @@ public class SydApi4j implements SydApi {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名(遵循 PKCS#7)
|
||||
* 使用指定的证书 DN,从加密设备获取对应的私钥证书,对指定的原始数据编制带公钥证书的数字签名(遵循 PKCS#7)。
|
||||
*
|
||||
* @param orgData 待签名数据
|
||||
* @param sCertDN 证书DN
|
||||
* @return
|
||||
* 符合PKCS7标准的签名结果
|
||||
*/
|
||||
@Override
|
||||
public String attachedSign(byte[] orgData, String sCertDN) {
|
||||
Proto8018 proto = new Proto8018(); //pset.getProtocolReqRender("75");
|
||||
byte[] dn = new byte[256];
|
||||
byte[] s = null;
|
||||
try {
|
||||
s = sCertDN.getBytes("GBK");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.arraycopy(s, 0, dn, 0, s.length);
|
||||
|
||||
// 填充数据
|
||||
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("DN", dn);
|
||||
data.put("infoData", orgData);
|
||||
|
||||
// 渲染发送
|
||||
ByteBuffer bb = proto.rend(packet);
|
||||
|
||||
synchronized (this) {
|
||||
// 响应解析
|
||||
bb = syncRead(syncSend(bb));
|
||||
}
|
||||
|
||||
Packet p = proto.parse(bb);
|
||||
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());
|
||||
}
|
||||
|
||||
return ((PacketSection) ret.get("signature")).getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 带公钥证书与原始数据的数字签名验签(遵循 PKCS#7)
|
||||
* 对指定的原始数据核验其带公钥证书签名。如签名有效(含证书无效)且需返回签名者公钥证书信息时,同时返回签名者公钥证书信息。
|
||||
*
|
||||
* @param sign 已签名数据
|
||||
* @return
|
||||
* 返回CERT_INFO结构的证书数据
|
||||
*/
|
||||
@Override
|
||||
public X509 attachedVerify(String sign) {
|
||||
Proto8019 proto = new Proto8019(); //pset.getProtocolReqRender("75");
|
||||
|
||||
// 填充数据
|
||||
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]))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PacketSection info = (PacketSection) ret.get("info");
|
||||
byte[] pCertInfo = info.getBytes();
|
||||
|
||||
String certInfo = new String(pCertInfo);
|
||||
int index = certInfo.indexOf("-----BEGIN CERTIFICATE-----");
|
||||
certInfo = certInfo.substring(index);
|
||||
// System.out.println("证书信息: " + certInfo);
|
||||
X509 x509 = GetX509CertInfo(certInfo);
|
||||
return x509;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------中移指令接口--------------------------------
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user