Ejemplo n.º 1
0
 /// <summary>
 /// 敏感信息解密
 /// </summary>
 /// <param name="encoder"></param>
 /// <returns></returns>
 public static string DecryptData(string data, Encoding encoding, SDKConfig con)
 {
     return(SecurityUtil.DecryptData(data, encoding, con));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 对待签名数据计算签名并赋值certid,signature字段返回签名后的报文
 /// </summary>
 /// <param name="reqData"></param>
 /// <param name="encoding"></param>
 /// <returns></returns>
 public static void Sign(Dictionary <string, string> reqData, Encoding encoding, SDKConfig s)
 {
     Sign(reqData, encoding, s.SignCertPath, s.SignCertPwd);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 持卡人信息域customerInfo构造,当勾选对敏感信息加密权限,启用新加密规范(对phoneNo,cvn2,expired加密)适用
        /// </summary>
        /// <param name="customerInfo">Dictionary的customerInfo</param>
        /// <param name="encoding">编码</param>
        /// <returns>string类型结果</returns>
        public static string GetCustomerInfoWithEncrypt(Dictionary <string, string> customerInfo, Encoding encoding, SDKConfig con)
        {
            if (customerInfo == null || customerInfo.Count == 0)
            {
                return("");
            }
            Dictionary <string, string> encryptedInfo = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> pair in customerInfo)
            {
                if (pair.Key == "phoneNo" || pair.Key == "cvn2" || pair.Key == "expired")
                {
                    encryptedInfo[pair.Key] = pair.Value;
                }
            }
            customerInfo.Remove("phoneNo");
            customerInfo.Remove("cvn2");
            customerInfo.Remove("expired");
            if (encryptedInfo.Count != 0)
            {
                string encryptedInfoStr = SDKUtil.CreateLinkString(encryptedInfo, false, false);
                encryptedInfoStr = SecurityUtil.EncryptData(encryptedInfoStr, encoding, con);
                customerInfo["encryptedInfo"] = encryptedInfoStr;
            }
            string customerInfoStr = "{" + SDKUtil.CreateLinkString(customerInfo, false, false) + "}";

            return(Convert.ToBase64String(encoding.GetBytes(customerInfoStr)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// http的基本post方法
        /// </summary>
        /// <param name="reqData">请求数据</param>
        /// <param name="url">URL地址</param>
        /// <param name="encoding">编码</param>
        /// <returns>服务器返回的数据</returns>
        public static Dictionary <String, String> Post(Dictionary <String, String> reqData, String reqUrl, Encoding encoding, SDKConfig s)
        {
            string postData = SDKUtil.CreateLinkString(reqData, false, true);

            byte[] byteArray = encoding.GetBytes(postData);
            try
            {
                if ("false".Equals(s.IfValidateRemoteCert)) //测试环境不验https证书
                {
                    System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
                }
                log.Info("发送post请求,url=[" + reqUrl + "],data=[" + postData + "]");
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(reqUrl);
                request.ContentType   = "application/x-www-form-urlencoded";
                request.Method        = "POST";
                request.ContentLength = byteArray.Length;
                request.ServicePoint.Expect100Continue = false;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(byteArray, 0, byteArray.Length);

                HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
                StreamReader    reader      = new StreamReader(webResponse.GetResponseStream(), encoding);
                String          sResult     = reader.ReadToEnd();

                requestStream.Close();
                reader.Close();
                webResponse.Close();
                if (webResponse.StatusCode == HttpStatusCode.OK)
                {
                    log.Info("收到后台应答,data=[" + sResult + "]");
                    return(SDKUtil.CoverStringToDictionary(sResult, encoding));
                }
                else
                {
                    string httpStatus = Enum.GetName(typeof(HttpStatusCode), webResponse.StatusCode);
                    log.Info("非200HTTP状态,httpStatus=" + httpStatus + ",data=[" + sResult + "]");
                    return(new Dictionary <string, string>());
                }
            }
            catch (Exception ex)
            {
                log.Error("post失败,异常:" + ex.Message);
                return(new Dictionary <string, string>());
            }
        }