This commit is contained in:
yihzhou 2022-11-08 17:12:05 +08:00
parent fd6ef6050f
commit ecd01a408e
2 changed files with 224 additions and 211 deletions

View File

@ -1726,7 +1726,6 @@ public class SydApi4j implements SydApi {
} }
/** /**
*
* @param e 原始错误 * @param e 原始错误
* @throws SydApiException * @throws SydApiException
*/ */
@ -2883,8 +2882,6 @@ public class SydApi4j implements SydApi {
} }
public RetWrap decryptDEByDNHsm(String certSerial, String pCipherKey) { public RetWrap decryptDEByDNHsm(String certSerial, String pCipherKey) {
certSerial = DnUtil.verifyDn(certSerial); certSerial = DnUtil.verifyDn(certSerial);
@ -3329,7 +3326,6 @@ public class SydApi4j implements SydApi {
} }
// 测试通过 // 测试通过
@Override @Override
public RetWrap decryptDE(boolean pFlag, int model, byte[] certSerial, String pCipherKey) { public RetWrap decryptDE(boolean pFlag, int model, byte[] certSerial, String pCipherKey) {
@ -3681,6 +3677,7 @@ public class SydApi4j implements SydApi {
/** /**
* 产生对称密钥通过清算所公钥证书加密生成数字信封 * 产生对称密钥通过清算所公钥证书加密生成数字信封
* 上清所 * 上清所
*
* @param pcDnEN: 清算所的公钥证书 * @param pcDnEN: 清算所的公钥证书
* @param pcDnSign会员的私钥证书 * @param pcDnSign会员的私钥证书
* @param pcData: 明文数据 * @param pcData: 明文数据
@ -3695,7 +3692,8 @@ public class SydApi4j implements SydApi {
HashMap<String, Object> packet = new HashMap<String, Object>(); HashMap<String, Object> packet = new HashMap<String, Object>();
packet.put("header", sn.getSn().array()); packet.put("header", sn.getSn().array());
HashMap<String, Object> data = new HashMap<String, Object>(); HashMap<String, Object> data = new HashMap<String, Object>();
try { data.put("alg$option", 3); try {
data.put("alg$option", 3);
//data.put("pFlag", "P"); //data.put("pFlag", "P");
data.put("certificateModel$option", 1); data.put("certificateModel$option", 1);
data.put("certificateDn", pcDnEN.getBytes("GBK")); data.put("certificateDn", pcDnEN.getBytes("GBK"));
@ -3713,8 +3711,6 @@ public class SydApi4j implements SydApi {
} }
packet.put("data", data); packet.put("data", data);
// 渲染发送 耗时长 // 渲染发送 耗时长
ByteBuffer bb = proto.rend(packet); ByteBuffer bb = proto.rend(packet);
@ -3741,9 +3737,11 @@ public class SydApi4j implements SydApi {
rw.put(SydApi.RET_KCV, ((PacketSection) ret.get("keyCheck")).getString()); rw.put(SydApi.RET_KCV, ((PacketSection) ret.get("keyCheck")).getString());
return (String) rw.get("CipherKey"); return (String) rw.get("CipherKey");
} }
/** /**
* 利用清算所公钥证书对签名数据进行验签接收用会员的私钥证书解密数字信封还原原文 * 利用清算所公钥证书对签名数据进行验签接收用会员的私钥证书解密数字信封还原原文
* 上清所 * 上清所
*
* @param pcDnDe: 会员的私钥证书 * @param pcDnDe: 会员的私钥证书
* @param pcDnVerify: 清算所公钥证书 * @param pcDnVerify: 清算所公钥证书
* @param pcSignData: 签名数字信封数据 * @param pcSignData: 签名数字信封数据
@ -3812,8 +3810,6 @@ public class SydApi4j implements SydApi {
} }
/** /**
* 用指定的证书私钥对指定的数据进行数字签名 * 用指定的证书私钥对指定的数据进行数字签名
* 网联 * 网联
@ -6457,7 +6453,6 @@ public class SydApi4j implements SydApi {
/** /**
* 使用SM4算法进行加密其中加密模式为CBC, * 使用SM4算法进行加密其中加密模式为CBC,
* 使用缺省值0X 00000000000000000000000000000000, * 使用缺省值0X 00000000000000000000000000000000,
* 补位模式为 PKCS5 PADDING * 补位模式为 PKCS5 PADDING
@ -11460,6 +11455,7 @@ public class SydApi4j implements SydApi {
private boolean attachedVerifyRSA(int rFlag, String sign) { private boolean attachedVerifyRSA(int rFlag, String sign) {
RetWrap ret = null; RetWrap ret = null;
boolean verifyRSA = false;
try { try {
ret = ASN1Util.takeOutOriginDataFromPKCS7Sign(sign); ret = ASN1Util.takeOutOriginDataFromPKCS7Sign(sign);
} catch (IOException e) { } catch (IOException e) {
@ -11471,7 +11467,13 @@ public class SydApi4j implements SydApi {
// byte[] pk = (byte[]) ret.get("pk"); // byte[] pk = (byte[]) ret.get("pk");
// byte[] hash = this.SM3Hash( Util.bytes2HexString( pk ), orgData ); // byte[] hash = this.SM3Hash( Util.bytes2HexString( pk ), orgData );
String sign2 = (String) ret.get("sign"); String sign2 = (String) ret.get("sign");
return this.detachedVerify( rFlag,0, orgData , sign2); if (orgData.length < 4096) {
verifyRSA= this.detachedVerify(rFlag, 1, orgData, sign2);
}else {
RetWrap hashData = this.countHash(0, 0, orgData, null);
verifyRSA= this.detachedVerify(2, 0, (byte[]) hashData.get("hash"), sign2);
}
return verifyRSA;
} }
@ -11513,10 +11515,10 @@ public class SydApi4j implements SydApi {
public String attachedSignRSASoft(int rFlag,byte[] orgData, String sCertDN) throws UnsupportedEncodingException { public String attachedSignRSASoft(int rFlag,byte[] orgData, String sCertDN) throws UnsupportedEncodingException {
sCertDN = DnUtil.verifyDn( sCertDN ); sCertDN = DnUtil.verifyDn( sCertDN );
String pk = this.GetDNPublicKey( SydApi.FOR_SIGN, sCertDN.getBytes("GBK") );
try { try {
byte[] hash = this.SM3Hash( pk, orgData ); RetWrap hashData = countHash(0, 0, orgData, null);
String sign = this.detachedSign(rFlag,0, hash, sCertDN); byte[] hash = (byte[]) hashData.get("hash");
String sign = this.detachedSign(2,0, hash, sCertDN);
return ASN1Util.addOriginDataToPKCS7Sign( orgData, sign ); return ASN1Util.addOriginDataToPKCS7Sign( orgData, sign );
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -82,6 +82,17 @@ public class Shanghairenhang {
}
@Test
public void testRenhang(){
System.setProperty("com.sunyard.sydapi4j.debug", "true");
SydApiBuilder builder = new SydApiBuilder().setIp("192.168.0.200");
SydApi4j api = (SydApi4j) builder.build();
String attachedSign = api.attachedSign(2,orgData2k, RSA);
System.out.println(attachedSign);
boolean attachedVerify = api.attachedVerify(2,attachedSign);
System.out.println(attachedVerify);
} }
} }