/// <summary> /// 证书方式签名(多证书时使用),指定证书路径。 /// </summary> /// <param name="reqData"></param> /// <param name="encoding">编码</param> /// <param name="certPath">证书路径</param> /// <param name="certPwd">证书密码</param> /// <returns></returns> public static void SignByCertInfo(Dictionary <string, string> reqData, string certPath, string certPwd, Encoding encoding) { if (!reqData.ContainsKey("signMethod")) { log.Error("signMethod must Not null"); return; } string signMethod = reqData["signMethod"]; if (!reqData.ContainsKey("version")) { log.Error("version must Not null"); return; } string version = reqData["version"]; if ("01".Equals(signMethod)) { reqData["certId"] = CertUtil.GetSignCertId(certPath, certPwd); //将Dictionary信息转换成key1=value1&key2=value2的形式 string stringData = SDKUtil.CreateLinkString(reqData, true, false, encoding); log.Info("待签名排序串:[" + stringData + "]"); if ("5.0.0".Equals(version)) { byte[] signDigest = SecurityUtil.Sha1(stringData, encoding); string stringSignDigest = SDKUtil.ByteArray2HexString(signDigest); log.Info("sha1结果:[" + stringSignDigest + "]"); byte[] byteSign = SecurityUtil.SignSha1WithRsa(CertUtil.GetSignKeyFromPfx(certPath, certPwd), encoding.GetBytes(stringSignDigest)); string stringSign = Convert.ToBase64String(byteSign); log.Info("5.0.0报文sha1RSA签名结果:[" + stringSign + "]"); //设置签名域值 reqData["signature"] = stringSign; } else { byte[] signDigest = SecurityUtil.Sha256(stringData, encoding); string stringSignDigest = SDKUtil.ByteArray2HexString(signDigest); log.Info("sha256结果:[" + stringSignDigest + "]"); byte[] byteSign = SecurityUtil.SignSha256WithRsa(CertUtil.GetSignKeyFromPfx(certPath, certPwd), encoding.GetBytes(stringSignDigest)); string stringSign = Convert.ToBase64String(byteSign); log.Info("5.1.0报文sha256RSA签名结果:[" + stringSign + "]"); //设置签名域值 reqData["signature"] = stringSign; } } else { log.Error("Error signMethod [" + signMethod + "] in SignByCertInfo. "); } }