コード例 #1
0
ファイル: AlipayNotify.cs プロジェクト: vasiliki02/le2le
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="inputPara">要解密数据</param>
        /// <returns>解密后结果</returns>
        public Dictionary <string, string> Decrypt(Dictionary <string, string> inputPara)
        {
            try
            {
                inputPara["notify_data"] = RSAFromPkcs8.decryptData(inputPara["notify_data"], _private_key, _input_charset);
            }
            catch (Exception e) { }

            return(inputPara);
        }
コード例 #2
0
        /// <summary>
        /// 解析远程模拟提交后返回的信息
        /// </summary>
        /// <param name="strText">要解析的字符串</param>
        /// <returns>解析结果</returns>
        public static Dictionary <string, string> ParseResponse(string strText)
        {
            //以“&”字符切割字符串
            string[] strSplitText = strText.Split('&');
            //把切割后的字符串数组变成变量与数值组合的字典数组
            Dictionary <string, string> dicText = new Dictionary <string, string>();

            for (int i = 0; i < strSplitText.Length; i++)
            {
                //获得第一个=字符的位置
                int nPos = strSplitText[i].IndexOf('=');
                //获得字符串长度
                int nLen = strSplitText[i].Length;
                //获得变量名
                string strKey = strSplitText[i].Substring(0, nPos);
                //获得数值
                string strValue = strSplitText[i].Substring(nPos + 1, nLen - nPos - 1);
                //放入字典类数组中
                dicText.Add(strKey, strValue);
            }

            if (dicText["res_data"] != null)
            {
                //解析加密部分字符串(RSA与MD5区别仅此一句)
                if (_sign_type == "0001")
                {
                    dicText["res_data"] = RSAFromPkcs8.decryptData(dicText["res_data"], _private_key, _input_charset);
                }

                //token从res_data中解析出来(也就是说res_data中已经包含token的内容)
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.LoadXml(dicText["res_data"]);
                    string strRequest_token = xmlDoc.SelectSingleNode("/direct_trade_create_res/request_token").InnerText;
                    dicText.Add("request_token", strRequest_token);
                }
                catch (Exception exp)
                {
                    dicText.Add("request_token", exp.ToString());
                }
            }

            return(dicText);
        }
コード例 #3
0
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="inputPara">要解密数据</param>
        /// <returns>解密后结果</returns>
        public Dictionary <string, string> Decrypt(Dictionary <string, string> inputPara)
        {
            try
            {
                var dd = inputPara["notify_data"];
                //logger.InfoFormat("Decrypt,之前:{0}", dd);
                var dr = RSAFromPkcs8.decryptData(dd, _private_key, _input_charset);
                //logger.InfoFormat("Decrypt,之后:{0}",  dr);
                inputPara["notify_data"] = dr;
            }
            catch (Exception exc)
            {
                logger.InfoFormat("DecryptException:{0}", exc.Message);
                throw;
            }

            return(inputPara);
        }