Ejemplo n.º 1
0
 public IHttpActionResult InsertData([FromBody] BCTktRefundSynVO request)
 {
     try
     {
         string requestIP = "IP为" + System.Web.HttpContext.Current.Request.UserHostAddress + "端口号为" + System.Web.HttpContext.Current.Request.Url.Port;
         string str1      = new JavaScriptSerializer().Serialize(request).Trim();
         string str1log   = System.DateTime.Now + " " + requestIP + " " + "请求加密数据:" + str1;
         LogHelper.WriteLog(str1log, "XinAGetData");
         string str2    = EnCryptAndDecipher.Encrypt(str1, "*****@*****.**", guid);
         string str2log = System.DateTime.Now + " " + "加密完成数据:" + str2;
         LogHelper.WriteLog(str2log, "XinAGetData");
         if (!string.IsNullOrEmpty(str2))
         {
             return(Json(new { SuccessFlag = true, Status = 200, Message = "加密成功!", EncryptGetData = guid + str2 }));
         }
         else
         {
             return(Json(new { SuccessFlag = false, Status = 500, Message = "加密失败!" }));
         }
     }
     catch (Exception ex)
     {
         string requestIP = "IP为" + System.Web.HttpContext.Current.Request.UserHostAddress + "端口号为" + System.Web.HttpContext.Current.Request.Url.Port;
         string message   = System.DateTime.Now + " " + requestIP + "加密异常信息:" + ex.StackTrace + " " + ex.Message;
         throw ex;
     }
 }
Ejemplo n.º 2
0
 public IHttpActionResult DecryptData([FromBody] BCTktRefundSynVO request)
 {
     try
     {
         //把加密结果解密出来验证解密是否正确
         //string str = HttpUtility.UrlDecode(request.RequestStr.ToString(),System.Text.Encoding.UTF8);
         string requestIP = "IP为" + System.Web.HttpContext.Current.Request.UserHostAddress + "端口号为" + System.Web.HttpContext.Current.Request.Url.Port;
         string data      = request.RequestStr;
         string datalog   = System.DateTime.Now + " " + requestIP + " " + "请求解密数据:" + data;
         LogHelper.WriteLog(datalog, "XinAGetData");
         string str2    = new JavaScriptSerializer().Serialize(data).Substring(0, 33).Replace("\"", "").ToString();
         string str2log = System.DateTime.Now + " " + "请求解密数据公钥:" + str2;
         LogHelper.WriteLog(str2log, "XinAGetData");
         if (!string.IsNullOrEmpty(str2) && str2.Length == 32)
         {
             string str3    = new JavaScriptSerializer().Serialize(data).Remove(0, 33).Replace("\"", "").ToString();
             string str3log = System.DateTime.Now + " " + "请求解密数据密文:" + str3;
             LogHelper.WriteLog(str3log, "XinAGetData");
             if (!string.IsNullOrEmpty(str3))
             {
                 string str1    = EnCryptAndDecipher.Decrypt(str3, "*****@*****.**", str2);
                 string str1log = System.DateTime.Now + " " + "解密成功数据:" + str1;
                 LogHelper.WriteLog(str1log, "XinAGetData");
                 XingAModel model = new XingAModel();
                 model.CreateTime       = System.DateTime.Now;
                 model.msgCode          = "1";
                 model.errMsg           = "测试数据";
                 model.EncryptGetData   = data.ToString();
                 model.DecryptGetData   = str1;
                 model.IsUseCreateOrder = 0;
                 int result = _XingAApp.AddData(model);
                 if (result > 0)
                 {
                     return(Json(new { SuccessFlag = true, Status = 200, Message = "解密成功!" }));
                 }
                 else
                 {
                     return(Json(new { SuccessFlag = false, Status = 500, Message = "解密失败,请检查解密数据!" }));
                 }
             }
             else
             {
                 return(Json(new { SuccessFlag = false, Status = 500, Message = "密文异常,请检查密文!" }));
             }
         }
         else
         {
             return(Json(new { SuccessFlag = false, Status = 500, Message = "公钥异常,请检查公钥!" }));
         }
     }
     catch (Exception ex)
     {
         string requestIP = "IP为" + System.Web.HttpContext.Current.Request.UserHostAddress + "端口号为" + System.Web.HttpContext.Current.Request.Url.Port;
         string message   = System.DateTime.Now + " " + requestIP + "解密异常信息:" + ex.StackTrace + ex.Message;
         LogHelper.WriteLog(message, "XinAGetData");
         throw ex;
     }
 }