Esempio n. 1
0
        /// <summary>
        /// 对待签名数据计算签名并赋值certid,signature字段返回签名后的报文
        /// </summary>
        /// <param name="reqData"></param>
        /// <param name="encoding">编码</param>
        /// <param name="certPath">证书路径</param>
        /// <param name="certPwd">证书密码</param>
        /// <returns></returns>
        public static void Sign(Dictionary <string, string> reqData, Encoding encoding, string certPath, string certPwd)
        {
            reqData["certId"] = CertUtil.GetSignCertId(certPath, certPwd);

            //将Dictionary信息转换成key1=value1&key2=value2的形式
            string stringData = SDKUtil.CreateLinkString(reqData, true, false);

            log.Info("待签名排序串:[" + stringData + "]");

            string stringSign = null;

            byte[] signDigest = SecurityUtil.Sha1X16(stringData, encoding);

            string stringSignDigest = BitConverter.ToString(signDigest).Replace("-", "").ToLower();

            log.Info("sha1结果:[" + stringSignDigest + "]");

            byte[] byteSign = SecurityUtil.SignBySoft(CertUtil.GetSignProviderFromPfx(certPath, certPwd), encoding.GetBytes(stringSignDigest));

            stringSign = Convert.ToBase64String(byteSign);
            log.Info("签名结果:[" + stringSign + "]");

            //设置签名域值
            reqData["signature"] = stringSign;
        }