save
This commit is contained in:
parent
ecd01a408e
commit
f345d47dd2
@ -115,6 +115,23 @@ public interface SydCertApi {
|
||||
*/
|
||||
RetWrap getAllCert(int dataFlag) throws UnsupportedEncodingException;
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有证书
|
||||
* @param dataFlag 数据包标志 0:起始包 1:中间包 2:结束包
|
||||
* @param sqlite 查询条件,默认查询所有"1=1"
|
||||
* @return
|
||||
* dataFlag: 数据包标志 0:起始包 1:中间包 2:结束包
|
||||
* certAllNum: 证书总数
|
||||
* realCertNum: 实际证书个数
|
||||
* dataAttrFlag: 数据包属性标志
|
||||
* certLenMax: 证书最大长度
|
||||
* certDNs: 证书DN
|
||||
*/
|
||||
RetWrap getAllCert(int dataFlag,String sqlite) throws UnsupportedEncodingException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上传指定证书到加密设备
|
||||
* @param certData 证书的字节数组
|
||||
|
||||
@ -877,6 +877,19 @@ public class SydApi4j implements SydApi {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean detachedVerifyRSA(int rFlag, int dataType, byte[] orgData, String sign) {
|
||||
boolean deVerify =false;
|
||||
if(orgData.length<4096){
|
||||
deVerify= detachedVerify(rFlag,dataType,orgData,sign);
|
||||
}else {
|
||||
RetWrap hashData = countHash(0, 0, orgData, null);
|
||||
deVerify= this.detachedVerify(2, 0, (byte[]) hashData.get("hash"), sign);
|
||||
}
|
||||
return deVerify;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean detachedVerify(int rFlag, int dataType, byte[] orgData, String sign) {
|
||||
Proto8006 proto = new Proto8006();
|
||||
@ -1061,6 +1074,21 @@ public class SydApi4j implements SydApi {
|
||||
}
|
||||
|
||||
|
||||
//人行大数据不指定摘要算法
|
||||
public String detachedSignRSA(int rFlag, int dataType, byte[] orgData, String sCertDN) {
|
||||
String sign =null;
|
||||
if(orgData.length<4096){
|
||||
sign = detachedSign(rFlag,dataType,orgData,sCertDN);
|
||||
}else{
|
||||
RetWrap hashData = countHash(0, 0, orgData, null);
|
||||
byte[] hash = (byte[]) hashData.get("hash");
|
||||
sign = detachedSign(2,0, hash, sCertDN);
|
||||
}
|
||||
return sign;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String detachedSign(int rFlag, int dataType, byte[] orgData, String sCertDN) {
|
||||
Proto8005 proto = new Proto8005();
|
||||
byte[] dn = new byte[256];
|
||||
@ -1282,7 +1310,73 @@ public class SydApi4j implements SydApi {
|
||||
}
|
||||
|
||||
r.put("certDNs", certs.toArray(new String[0]));
|
||||
// r.put("certDNlist", certs);
|
||||
r.put("certDNlist", certs);
|
||||
|
||||
return r;
|
||||
}
|
||||
// 测试通过
|
||||
@Override
|
||||
public RetWrap getAllCert(int dataFlag,String sqlite) throws UnsupportedEncodingException {
|
||||
Proto8008 proto = new Proto8008();
|
||||
|
||||
// 填充数据
|
||||
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("dataFlag$option", dataFlag);
|
||||
|
||||
String sqlite3 = "1 = 1 ";
|
||||
data.put("sqlite3", sqlite3);
|
||||
|
||||
// 渲染发送
|
||||
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());
|
||||
}
|
||||
|
||||
RetWrap r = new RetWrap();
|
||||
|
||||
PacketSection resDataFlag = (PacketSection) ret.get("dataFlag");
|
||||
r.put("dataFlag", (int) resDataFlag.getBytes()[0]);
|
||||
PacketSection certAllNum = (PacketSection) ret.get("certAllNum");
|
||||
r.put("certAllNum", (int) certAllNum.getBytes()[0]);
|
||||
PacketSection realCertNum = (PacketSection) ret.get("realCertNum");
|
||||
r.put("realCertNum", (int) realCertNum.getBytes()[0]);
|
||||
PacketSection dataAttrFlag = (PacketSection) ret.get("dataAttrFlag");
|
||||
r.put("dataAttrFlag", (int) dataAttrFlag.getBytes()[0]);
|
||||
r.put("certLenMax", Integer.parseInt(Util.bytes2HexString(Util.toArray(bb)).substring(60, 62), 16));
|
||||
|
||||
List<String> certs = new ArrayList<String>();
|
||||
while (bb.limit() - bb.position() >= 128) {
|
||||
byte[] cert = new byte[128];
|
||||
bb.get(cert);
|
||||
certs.add(new String(cert, "GBK"));
|
||||
}
|
||||
|
||||
r.put("certDNs", certs.toArray(new String[0]));
|
||||
r.put("certDNlist", certs);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -21,12 +21,12 @@ import java.util.List;
|
||||
import static com.sunyard.sydapi.util.PrintUtil.printRetWrap;
|
||||
|
||||
public class Shanghairenhang {
|
||||
private static final byte[] orgData2k = new byte[ 5*1024 ];
|
||||
private static final byte[] orgData2k = new byte[ 100 ];
|
||||
private static final String pcDnEN = "C=CN,O=CFCA OCA1,OU=YCCA,OU=Individual-2,CN=YCCA@黄金交易所@Zhuangj@1";
|
||||
private static final String RSA = "C=cn,O=CFCA TEST CA,OU=NCS2,OU=Enterprises,CN=041@Z402451000010@ShanDong@00000001";
|
||||
|
||||
public static void main(String[] args) throws UnsupportedEncodingException, CertificateException, NoSuchProviderException {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
//System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
long startTime = System.currentTimeMillis(); //获取开始时间
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.0.200");
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
@ -95,4 +95,20 @@ public class Shanghairenhang {
|
||||
System.out.println(attachedVerify);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCerts() throws UnsupportedEncodingException {
|
||||
System.setProperty("com.sunyard.sydapi4j.debug", "true");
|
||||
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.1.129");
|
||||
SydApi4j api = (SydApi4j) builder.build();
|
||||
RetWrap allCert = api.getAllCert(0,"");
|
||||
printRetWrap(allCert);
|
||||
String[] certDNs =(String[]) allCert.get("certDNs");
|
||||
ArrayList<String> certlist = new ArrayList<String>();
|
||||
Collections.addAll(certlist, certDNs);
|
||||
System.out.println("aaa:"+certDNs[0]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user