private void UnPackProtocol(byte[] msg_bytes) { ByteBuffer buffer = new ByteBuffer(Encrypt.Decode(msg_bytes, Encrypt.DefaultKey)); //读出附加位 int addition = buffer.ReadInt(); //读出用户ID列表 int list_lenght = buffer.ReadInt(); //读出协议体 byte[] protocol_bytes = buffer.ReadBytes((int)buffer.RemainingBytes()); IMessage protocol = Protocol.Decode(protocol_bytes); buffer.Close(); if (protocol != null) { Debug.Log("客户端接收消息:" + protocol.GetType() + " 数据:" + protocol.ToString()); lock (msg_lock) { this.protocol_list.Add(protocol); } } }
/// <summary> /// 默认读取数据库连接信息中的数据库信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <summary> /// 读取数据库连接信息中的数据库信息 /// </summary> private void readDataBase() { string conectDataBase = "myConection"; string conectPlugDataBase = "plugConection"; if (ConfigurationManager.ConnectionStrings[conectDataBase] != null) { string conString = ConfigurationManager.ConnectionStrings[conectDataBase].ToString(); string deConString = Encrypt.Decode(conString); int dataBaseIndex = deConString.IndexOf("Catalog="); int UserIndex = deConString.IndexOf(";User"); } else { } if (ConfigurationManager.ConnectionStrings[conectPlugDataBase] != null) { string conString = ConfigurationManager.ConnectionStrings[conectPlugDataBase].ToString(); string deConString = Encrypt.Decode(conString); int dataBaseIndex = deConString.IndexOf("Catalog="); int UserIndex = deConString.IndexOf(";User"); this.lbl_plugStatus.Text = deConString.Substring(dataBaseIndex + 8, UserIndex - (dataBaseIndex + 8)); this.lbl_plugStatus.ForeColor = Color.Green; } else { this.lbl_plugStatus.Text = "未配置"; this.lbl_plugStatus.ForeColor = Color.Red;; } }
public void Test002() { var enc = new Encrypt(); var secret = enc.Encode((string)null); var decode = enc.Decode(secret); Assert.AreEqual(null, decode); }
public void Test001() { var enc = new Encrypt(); var secret = enc.Encode(""); var decode = enc.Decode(secret); Assert.AreEqual("", decode); }
public void Test005() { var enc = new Encrypt(); var plane = "祇園精舎の鐘の声+諸行無常の響き有り-沙羅双樹の花の色_盛者必衰の理を現す|奢れる人も久からず-ただ春の夜の夢のごとし:猛き者も遂には滅びぬ--ひとへに風の前の塵に同じ+"; var secret = enc.Encode(plane); var decode = enc.Decode(secret); Assert.AreEqual(plane, decode); }
public void Test006() { var enc = new Encrypt(); var text = "月日は百代の過客にして、行交う年もまた旅人也。"; var dplane = Encoding.UTF8.GetBytes(text); var dsec = enc.Encode(dplane); var dplane2 = enc.Decode(dsec); var text2 = Encoding.UTF8.GetString(dplane2); Assert.AreEqual(text, text2); }
/// <summary> /// Get Value from scrambled cookie /// </summary> /// <param name="key">Cookie key</param> /// <param name="def">default value if there is no key</param> /// <returns>value as plane text</returns> public string GetCookieSecure(string key, string def = "") { var base64 = Controller.Request.Cookies[key]; if (string.IsNullOrEmpty(base64)) { return(def); } else { var sec = Convert.FromBase64String(base64); var buf = encrypt.Decode(sec); buf = new Compression().Decompress(buf); var cleanText = Encoding.UTF8.GetString(buf); return(cleanText); } }
public static SettingModel LoadSetting() { var sec = (string)ConfigRegister.Current["Settings", ""]; if (sec != "") { var enc = new Encrypt(); var json = enc.Decode(sec); var ret = JsonSerializer.Deserialize <SettingModel>(json); ret = Migration(ret); return(ret); } else { return(new SettingModel()); } }
/// <summary> /// 返回sqlConnection,默认连接字符串名称是“businessConection” /// </summary> /// <returns></returns> public static SqlConnection sqlConnection() { try { string conString = ConfigurationManager.ConnectionStrings["businessConection"].ToString(); string deConString = Encrypt.Decode(conString); //ConnectionStringSettings conStrings = new ConnectionStringSettings("busynessDate", deConString); SqlConnection sqlConnection = new SqlConnection(deConString); return(sqlConnection); } catch (Exception ex) { MessageBox.Show("数据库连接出错" + ex.Message + ex.InnerException); return(null); } }
public void Test004() { var enc = new Encrypt(); for (int cnt = 0; cnt < 3; cnt++) { var planeBuild = new StringBuilder(); for (var i = MathUtil.Rand(10000, 11000); i >= 0; i--) { planeBuild.Append((char)MathUtil.Rand(' ', '~')); } var plane = planeBuild.ToString(); var secret = enc.Encode(plane); Assert.IsTrue(secret?.Length > 0); var decode = enc.Decode(secret); Assert.AreEqual(plane, decode); } }
/// <summary> /// 更新可发起抽奖的次数 /// </summary> /// <returns></returns> protected bool UpdatePubishingEnableTimes() { string times = string.Empty; //if (Session["publishTimes"] != null) //{ // int timesvalue = 0; // if (int.TryParse(Session["publishTimes"].ToString(), out timesvalue)) // { // Session["publishTimes"] = timesvalue - 1; // return true; // } // else // { // return false; // } //} //else //{ // return false; //} HttpCookie pubcookie = Cookie.Get("publishTimes"); if (pubcookie != null) { int timesvalue = 0; if (int.TryParse(Encrypt.Decode(pubcookie.Value.ToString()), out timesvalue)) { pubcookie.Expires = DateTime.Now.AddDays(-1); Cookie.Save("publishTimes", Encrypt.Encode((timesvalue - 1).ToString()), 24); return(true); } else { return(false); } } else { return(false); } }
private void UnPackProtocol(byte[] msg_bytes, int connect_id) { ByteBuffer buffer = new ByteBuffer(Encrypt.Decode(msg_bytes, Encrypt.DefaultKey)); //读出附加位 int addition = buffer.ReadInt(); //读出用户ID列表 List <int> player_id_list = new List <int>(); int list_lenght = buffer.ReadInt(); for (int i = 1; i <= list_lenght; i++) { int user_id = buffer.ReadInt(); player_id_list.Add(user_id); } //读出协议体 byte[] protocol_bytes = buffer.ReadBytes((int)buffer.RemainingBytes()); IMessage protocol = Protocol.Decode(protocol_bytes); buffer.Close(); if (protocol != null) { Log.Debug("服务端接收消息:" + protocol.GetType() + " 数据:" + protocol.ToString()); ProtocolInfo mProtocolInfo = new ProtocolInfo(); mProtocolInfo.Protocol = protocol; mProtocolInfo.ConnectId = connect_id; mProtocolInfo.Addition = addition; mProtocolInfo.PlayerIdList = player_id_list; lock (msg_lock) { this.protocol_list.Add(mProtocolInfo); } } }
/// <summary> /// 默认读取数据库连接信息中的数据库信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <summary> /// 读取数据库连接信息中的数据库信息 /// </summary> private void readDataBase() { string businessDbConnectStringKey = DataSourceType.business.ToString(); string plugDbConnectStringKey = DataSourceType.plug.ToString(); if (ConfigurationManager.ConnectionStrings[plugDbConnectStringKey] != null) { string conString = ConfigurationManager.ConnectionStrings[plugDbConnectStringKey].ToString(); string deConString = Utility.Encrypt.Decode(conString); int dataBaseIndex = deConString.IndexOf("Catalog="); int UserIndex = deConString.IndexOf(";User"); this.lblPlug.Text = deConString.Substring(dataBaseIndex + 8, UserIndex - (dataBaseIndex + 8)); this.lblPlug.ForeColor = Color.Green; } else { this.lblPlug.Text = "未配置"; this.lblPlug.ForeColor = Color.Red;; } if (ConfigurationManager.ConnectionStrings[businessDbConnectStringKey] != null) { string conString = ConfigurationManager.ConnectionStrings[businessDbConnectStringKey].ToString(); string deConString = Encrypt.Decode(conString); int dataBaseIndex = deConString.IndexOf("Catalog="); int UserIndex = deConString.IndexOf(";User"); this.lblBusiness.Text = deConString.Substring(dataBaseIndex + 8, UserIndex - (dataBaseIndex + 8)); this.lblBusiness.ForeColor = Color.Green; } else { this.lblBusiness.Text = "未配置"; this.lblBusiness.ForeColor = Color.Red;; } }
/// <summary> /// 返回sqlConnection, /// 业务数据源连接字符串名称是“business”, /// 外挂数据源连接字符串名称是“plug", /// U8数据源连接字符串名称是“u8" /// 运维数据源连接字符串名称是“it" /// 与数据源枚举一致 /// </summary> /// <param name="dataSourceType" > /// 数据源类型 /// </param> /// <returns></returns> public static SqlConnection sqlConnection(DataSourceType dataSourceType) { string conString; string deConString; SqlConnection sqlConnection; if (dataSourceType == DataSourceType.u8) { string connectedKey = Enum.GetName(typeof(DataSourceType), DataSourceType.u8); conString = ConfigurationManager.ConnectionStrings[connectedKey].ToString(); deConString = Encrypt.Decode(conString); sqlConnection = new SqlConnection(deConString); return(sqlConnection); } if (dataSourceType == DataSourceType.ufsystem) { string connectedKey = Enum.GetName(typeof(DataSourceType), DataSourceType.ufsystem); conString = ConfigurationManager.ConnectionStrings[connectedKey].ToString(); deConString = Encrypt.Decode(conString); sqlConnection = new SqlConnection(deConString); return(sqlConnection); } if (dataSourceType == DataSourceType.it) { string connectedKey = Enum.GetName(typeof(DataSourceType), DataSourceType.it); conString = ConfigurationManager.ConnectionStrings[connectedKey].ToString(); deConString = Encrypt.Decode(conString); sqlConnection = new SqlConnection(deConString); return(sqlConnection); } else { if (dataSourceType == DataSourceType.plug) { string connectedKey = Enum.GetName(typeof(DataSourceType), DataSourceType.plug); conString = ConfigurationManager.ConnectionStrings[connectedKey].ToString(); deConString = Encrypt.Decode(conString); sqlConnection = new SqlConnection(deConString); return(sqlConnection); } conString = ConfigurationManager.ConnectionStrings[Enum.GetName(typeof(DataSourceType), DataSourceType.business)].ToString(); //conString = ConfigurationManager.ConnectionStrings[connectedKey].ToString(); deConString = Encrypt.Decode(conString); sqlConnection = new SqlConnection(deConString); return(sqlConnection); } }
private void timer1_Tick(object sender, EventArgs e) { //1秒跑一次的程序1 //1秒跑一次的程序2 if (richTextBox1.Text.Contains("\n")) { try { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start();//开始计时 var richText = richTextBox1.Text.Split('\n'); //解析扫码数据,拿取关键信息 string jsonText = richText[0]; //二维码解密 jsonText = Encrypt.Decode(jsonText); //json格式化 JavaScriptObject jsonObj = JavaScriptConvert.DeserializeObject <JavaScriptObject>(jsonText); personId = jsonObj["Id"].ToString(); var personCardId = jsonObj["Num"].ToString();//身份证号码 staffEnum = jsonObj["staffEnum"].ToString(); var WorkerStaffEnum = ""; try { WorkerStaffEnum = jsonObj["WorkerStaffEnum"].ToString(); } catch (Exception) { } Object o_result = null; //检查是否存在这个人 //DataRow[] selectedResult = PcTable.Select("Id=" + personId); if (staffEnum == "Police") { string select_Exist_pc = "select * from Cater.PCStaff where [Id]='" + personId + "'"; o_result = SqlHelper.ExecuteScalar(select_Exist_pc); } else if (staffEnum == "Family") { o_result = 1; } else { string select_Exist_worker = "select * from Cater.WorkerStaff where [Id]='" + personId + "'"; o_result = SqlHelper.ExecuteScalar(select_Exist_worker); } // DataRow[] selectedResult_worker = WorkerTable.Select("Id=" + personId); if (o_result == null) { richTextBox1.Text = ""; label2.Font = new Font("宋体粗体", 50); label2.ForeColor = Color.Red; label2.Text = "查无此人"; return; } //检查是否重复刷卡 if (OverPay(personId, TempOrderId.ToString(), staffEnum)) { richTextBox1.Text = ""; label2.Text = "重复扫码!"; SpeechVideo_Read(0, 100, "重复扫码!"); return; } //查看是否过期以及余额是否足够 string imforUrl = null; if (staffEnum == "Police") { imforUrl = "http://" + Properties.Settings.Default.header_url + @"/Interface/PC/GetPcStaff.ashx?InformationNum=" + personCardId; } else if (staffEnum == "Worker") { imforUrl = "http://" + Properties.Settings.Default.header_url + "/Interface/Worker/GetWorkerStaff.ashx?informationNum=" + personCardId; } string money = null; //如果是家属不做判断 if (staffEnum != "Family") { string dateResponse = ""; try { dateResponse = GetFunction(imforUrl);//拿取余额以及有效期 } catch (Exception) { richTextBox1.Text = ""; label2.Text = "网络错误"; return; } JavaScriptObject jsonResponse2 = JavaScriptConvert.DeserializeObject <JavaScriptObject>(dateResponse); JavaScriptObject json; if (staffEnum == "Police") { json = (JavaScriptObject)jsonResponse2["pcInfo"]; } else { json = (JavaScriptObject)jsonResponse2["workerInfo"]; } var effectDate = json["ValidityDate"]; if (effectDate != null) { TimeSpan ts = Convert.ToDateTime(effectDate.ToString().Split('T')[0]) - DateTime.Now; if (ts.Hours < 0) { label2.Text = "用户已过期!"; richTextBox1.Text = ""; SpeechVideo_Read(0, 100, "用户已过期!"); return; } } money = json["Amount"].ToString(); double tempChangePrice = 0; if (staffEnum == "Police") { tempChangePrice = Recent_Price; } switch (WorkerStaffEnum) { case "Worker": switch (currentCat) { case "Breakfast": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Worker_Breakfast"]); break; case "Lunch": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Worker_Lunch"]); break; case "Supper": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Worker_Supper"]); break; } break; case "Stationed": switch (currentCat) { case "Breakfast": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Stationed_Breakfast"]); break; case "Lunch": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Stationed_Lunch"]); break; case "Supper": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Stationed_Supper"]); break; } break; case "Emploee": switch (currentCat) { case "Breakfast": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Emploee_Breakfast"]); break; case "Lunch": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Emploee_Lunch"]); break; case "Supper": tempChangePrice = Convert.ToDouble(allPriceJsonObj["Common_WorkerStaff_Emploee_Supper"]); break; } break; default: break; } if ((Convert.ToDouble(money) - tempChangePrice) < 0) { label2.Text = "余额不足!"; richTextBox1.Text = ""; SpeechVideo_Read(0, 100, "余额不足!"); return; } } //接口拿照片 string picUrl = "http://" + Properties.Settings.Default.header_url + "/Interface/Icon/GetStaffIconByIpAddr.ashx?id=" + personId + "&staffType=" + staffEnum.ToLower() + "&addr=" + Properties.Settings.Default.header_url; try { string picResponse = GetFunction(picUrl);//照片url回复 // json格式化 JavaScriptObject jsonResponse = JavaScriptConvert.DeserializeObject <JavaScriptObject>(picResponse); string responPicUrl = jsonResponse["icon"].ToString(); //var ddd = json["Icon"].ToString(); pictureBox1.Image = new Bitmap(new WebClient().OpenRead(responPicUrl)); } catch (Exception) { pictureBox1.Image = Properties.Resources.EMyty; label2.Text = "拿取照片错误!"; } //显示扫码成功!大字体 richTextBox1.Text = ""; label2.Font = new Font("宋体粗体", 50); label2.ForeColor = Color.GreenYellow; label2.Text = "扫码成功!"; SpeechVideo_Read(0, 100, "扫码成功!"); if (staffEnum != "家属") { label2.Text = "消费前余额:" + money.ToString() + "元"; } label1.Text = (Convert.ToInt16(label1.Text) + 1).ToString(); //扫码成功写入xml文件 //AppendXml(staffEnum, personId, whole_catlocation.ToString(), TempOrderId.ToString(), // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //扫码成功写入数据库 InsertRecoed(staffEnum, personId, whole_catlocation.ToString(), TempOrderId.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); AllowTakeOrderBool = false; TakeOrderBool = false; watch.Stop(); //停止计时 Console.WriteLine("耗时:" + (watch.ElapsedMilliseconds)); //输出时间 毫秒 } catch (Exception) { richTextBox1.Text = ""; label2.Text = "请出示正确的二维码"; SpeechVideo_Read(0, 100, "扫码错误!"); } //写入文本,写入记录 } //20秒跑一次程序 if (timer_count_10s >= 10) { if (label2.Text == "扫码成功!" || label2.Text == "重复扫码!") { label2.Text = ""; } timer_count_10s = 0; } else { timer_count_10s++; } }
protected void Page_Load(object sender, EventArgs e) { Response.Write(Encrypt.Decode("C4-CA-42-38-A0-B9-23-82-0D-CC-50-9A-6F-75-84-9B", "xgcrm001")); }
private void timer1_Tick(object sender, EventArgs e) { //1秒跑一次的程序 if (AllowTakeOrderBool == true) { if (button1.Enabled == false) { button1.Enabled = true; } } //1秒跑一次的程序2 if (richTextBox1.Text.Contains("\n")) { if (foodDic.Count == 0) { richTextBox1.Clear(); MessageBox.Show("请选择至少一个菜品"); return; } try { //解析扫码数据,拿取关键信息 var richText = richTextBox1.Text.Split('\n'); //二维码解码 var jsonText = Encrypt.Decode(richText[0]); //json数据格式整理 JavaScriptObject jsonObj = JavaScriptConvert.DeserializeObject <JavaScriptObject>(jsonText); Temp_pcNum = jsonObj["Num"].ToString(); personId = jsonObj["Id"].ToString(); staffEnum = jsonObj["staffEnum"].ToString(); var personCardId = jsonObj["Num"].ToString();//身份证号码 //如果是家属 则return if (staffEnum == "Family") { richTextBox1.Text = ""; MessageBox.Show("家属不可打包"); return; } //检查是否存在这个人 Object o_result = null; //检查是否存在这个人 //DataRow[] selectedResult = PcTable.Select("Id=" + personId); if (staffEnum == "Police") { string select_Exist_pc = "select * from Cater.PCStaff where [Id]='" + personId + "'"; o_result = SqlHelper.ExecuteScalar(select_Exist_pc); } else { string select_Exist_worker = "select * from Cater.WorkerStaff where [Id]='" + personId + "'"; o_result = SqlHelper.ExecuteScalar(select_Exist_worker); } if (o_result == null) { richTextBox1.Text = ""; label2.Font = new Font("宋体粗体", 30); label2.ForeColor = Color.Red; label2.Text = "查无此人"; OrderFoodList.Clear(); OrderFoodPrice.Clear(); // ButtonNumClear(); foodDic.Clear(); Refresh(); return; } //查看是否过期以及余额是否足够 string imforUrl = null; if (staffEnum == "Police") { imforUrl = "http://" + Properties.Settings.Default.header_url + @"/Interface/PC/GetPcStaff.ashx?InformationNum=" + personCardId; } else { imforUrl = "http://" + Properties.Settings.Default.header_url + "/Interface/Worker/GetWorkerStaff.ashx?informationNum=" + personCardId; } string dateResponse = ""; try { dateResponse = GetFunction(imforUrl);//照片url回复 } catch (Exception ex) { richTextBox1.Text = ""; label2.Text = "网络错误"; OrderFoodList.Clear(); OrderFoodPrice.Clear(); //ButtonNumClear(); foodDic.Clear(); Refresh(); return; } JavaScriptObject jsonResponse2 = JavaScriptConvert.DeserializeObject <JavaScriptObject>(dateResponse); JavaScriptObject json; if (jsonResponse2["Msg"].ToString() == "失败") { richTextBox1.Text = ""; label2.Text = "账号验证失败"; OrderFoodList.Clear(); OrderFoodPrice.Clear(); //ButtonNumClear(); foodDic.Clear(); Refresh(); return; } if (staffEnum == "Police") { json = (JavaScriptObject)jsonResponse2["pcInfo"]; } else { json = (JavaScriptObject)jsonResponse2["workerInfo"]; } var effectDate = json["ValidityDate"]; if (effectDate != null) { TimeSpan ts = Convert.ToDateTime(effectDate.ToString().Split('T')[0]) - DateTime.Now; if (ts.Hours < 0) { label2.Text = "用户已过期!"; richTextBox1.Text = ""; SpeechVideo_Read(0, 100, "用户已过期!"); OrderFoodList.Clear(); OrderFoodPrice.Clear(); foodDic.Clear(); Refresh(); //ButtonNumClear(); return; } } string money = json["Amount"].ToString(); if ((Convert.ToDouble(money) - Convert.ToDouble(priceSum())) < 0) { label2.Text = "余额不足!"; richTextBox1.Text = ""; SpeechVideo_Read(0, 100, "余额不足!"); OrderFoodList.Clear(); OrderFoodPrice.Clear(); //ButtonNumClear(); foodDic.Clear(); Refresh(); return; } //显示扫码成功!大字体 richTextBox1.Text = ""; label2.Font = new Font("宋体粗体", 30); label2.ForeColor = Color.Green; label2.Text = "扫码成功!"; SpeechVideo_Read(0, 100, "扫码成功!"); //ButtonNumClear(); //扫码成功写入数据库 string foodstring = null; foreach (var item in foodDic) { var str = item.Key; str = str.Substring(0, str.Length - 1); //定义正则表达式规则 Regex reg = new Regex(@"\d+\.\d+"); //返回一个结果集,找出菜名字! MatchCollection result = reg.Matches(str); str = str.Replace(result[0].Value, ""); //查数据库找出detailID var selectID = SqlHelper.ExecuteScalar(@"SELECT [Id] FROM[XinYuSiteDB].[Cater].[CookbookSetInDateDetail] where CookbookDateId = '" + TempOrderId + "' and CookbookName = '" + str + "'"); foodstring += selectID + ","; } foodstring = foodstring.Substring(0, foodstring.Length - 1); //计算总价 string orderPrice = priceSum(); InsertRecoed(staffEnum, personId, whole_catlocation.ToString(), TempOrderId.ToString(), foodstring, orderPrice, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //还原buuton的enable状态! Return_Button(); //清楚已选列表 OrderFoodList.Clear(); OrderFoodPrice.Clear(); foodDic.Clear(); Refresh(); } catch (Exception EX) { MessageBox.Show(EX.Message); richTextBox1.Text = ""; // MessageBox.Show(EX.Message); label2.Text = "请出示正确的二维码"; SpeechVideo_Read(0, 100, "扫码错误!"); OrderFoodList.Clear(); OrderFoodPrice.Clear(); //ButtonNumClear(); Return_Button(); } //写入文本,写入记录 } }