public static void SignByCertInfo(Dictionary <string, string> dictionary, string certId, ICipherParameters key) { if (!dictionary.ContainsKey("signMethod")) { throw new UnionPayException("signMethod must Not null"); } if (!dictionary.ContainsKey("version")) { throw new UnionPayException("version must Not null"); } var signMethod = dictionary["signMethod"]; if ("01" == signMethod) { dictionary["certId"] = certId; var stringData = GetSignContent(dictionary, true, false); var stringSignDigest = SHA256.Compute(stringData); var stringSign = SHA256WithRSA.SignData(stringSignDigest, key); //设置签名域值 dictionary["signature"] = stringSign; } else { throw new UnionPayException("Error signMethod [" + signMethod + "] in SignByCertInfo. "); } }
public static void SignByCertInfo(Dictionary <string, string> reqData, string certId, AsymmetricKeyParameter parameters) { if (!reqData.ContainsKey("signMethod")) { throw new Exception("signMethod must Not null"); } var signMethod = reqData["signMethod"]; if (!reqData.ContainsKey("version")) { throw new Exception("version must Not null"); } var version = reqData["version"]; if ("01".Equals(signMethod)) { reqData["certId"] = certId; var stringData = GetSignContent(reqData, true, false); var stringSignDigest = SHA256.Compute(stringData); var stringSign = SHA256WithRSA.SignData(stringSignDigest, parameters); //设置签名域值 reqData["signature"] = stringSign; } else { throw new Exception("Error signMethod [" + signMethod + "] in SignByCertInfo. "); } }