Beispiel #1
0
        /// <summary>
        /// 将customerInfo转化为Dictionary,为方便处理,encryptedInfo下面的信息也均转换为customerInfo子域一样方式处理
        /// </summary>
        /// <param name="customerInfoStr">string的customerInfo</param>
        /// <param name="encoding">编码</param>
        /// <returns>Dictionary类型结果</returns>
        public static Dictionary <string, string> ParseCustomerInfo(string customerInfoStr, Encoding encoding)
        {
            if (customerInfoStr == null || customerInfoStr.Trim().Equals(""))
            {
                return(new Dictionary <string, string>());
            }
            string s = null;

            try
            {
                s = encoding.GetString(Convert.FromBase64String(customerInfoStr));
            }
            catch (Exception e)
            {
                log.Error("customerInfoStr解析失败,异常:" + e.Message);
                return(new Dictionary <string, string>());
            }
            s = s.Substring(1, s.Length - 2);
            Dictionary <string, string> customerInfo = SDKUtil.parseQString(s, encoding);

            if (customerInfo.Keys.Contains("encryptedInfo"))
            {
                string encryptedInfoStr = customerInfo["encryptedInfo"];
                customerInfo.Remove("encryptedInfo");
                encryptedInfoStr = SecurityUtil.DecryptData(encryptedInfoStr, encoding);
                Dictionary <string, string> encryptedInfo = SDKUtil.parseQString(encryptedInfoStr, encoding);
                foreach (KeyValuePair <string, string> pair in encryptedInfo)
                {
                    customerInfo[pair.Key] = pair.Value;
                }
            }
            return(customerInfo);
        }
Beispiel #2
0
        /// <summary>
        /// 对控件支付成功返回的结果信息中data域进行验签(控件端获取的应答信息)
        /// </summary>
        /// <param name="jsonData">json格式数据,例如:{"sign" : "J6rPLClQ64szrdXCOtV1ccOMzUmpiOKllp9cseBuRqJ71pBKPPkZ1FallzW18gyP7CvKh1RxfNNJ66AyXNMFJi1OSOsteAAFjF5GZp0Xsfm3LeHaN3j/N7p86k3B1GrSPvSnSw1LqnYuIBmebBkC1OD0Qi7qaYUJosyA1E8Ld8oGRZT5RR2gLGBoiAVraDiz9sci5zwQcLtmfpT5KFk/eTy4+W9SsC0M/2sVj43R9ePENlEvF8UpmZBqakyg5FO8+JMBz3kZ4fwnutI5pWPdYIWdVrloBpOa+N4pzhVRKD4eWJ0CoiD+joMS7+C0aPIEymYFLBNYQCjM0KV7N726LA==",  "data" : "pay_result=success&tn=201602141008032671528&cert_id=68759585097"}</param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public static bool ValidateAppResponse(string jsonData, Encoding encoding)
        {
            log.Info("控件返回报文验签:[" + jsonData + "]");
            //获取签名
            Dictionary <string, object> data = SDKUtil.JsonToDictionary(jsonData);

            string stringData = (string)data["data"];
            string signValue  = (string)data["sign"];
            Dictionary <string, string> dataMap = SDKUtil.parseQString(stringData, encoding);

            byte[] signByte         = Convert.FromBase64String(signValue);
            byte[] signDigest       = SecurityUtil.Sha1X16(stringData, encoding);
            string stringSignDigest = BitConverter.ToString(signDigest).Replace("-", "").ToLower();

            log.Debug("sha1结果:[" + stringSignDigest + "]");
            RSACryptoServiceProvider provider = CertUtil.GetValidateProviderFromPath(dataMap["cert_id"]);

            if (null == provider)
            {
                log.Error("未找到证书,无法验签,验签失败。");
                return(false);
            }
            bool result = SecurityUtil.ValidateBySoft(provider, signByte, encoding.GetBytes(stringSignDigest));

            if (result)
            {
                log.Info("验签成功");
            }
            else
            {
                log.Info("验签失败");
            }
            return(result);
        }