private void btnLogin_Click(object sender, RoutedEventArgs e) { if (cbRemember.IsChecked.HasValue && (bool)cbRemember.IsChecked) { DataUtil.Config.SaveAccounts(cbUsername.Text, tbPassword.Password, cbGameServer.SelectedIndex); } DESHelper des = new DESHelper(); DataUtil.Config.currentAccount.username = des.Encrypt(cbUsername.Text); DataUtil.Config.currentAccount.password = des.Encrypt(tbPassword.Password); DataUtil.Config.currentAccount.gameServer = cbGameServer.SelectedIndex; ((MainWindow)(Owner)).StartGame(); Close(); }
public void Get() { var model = new HouseBackupDto() { HouseId = "SHQPS000000001", District = DistrictEnumer.QingPu, CertificateNumber = "青1234123456", Trustor = "张三", Sex = 1, MobilePhone = "13712345678", CommissionStartDate = DateTime.Now, AreaName = "小区", IsLease = HireState.No, RoomTypeString = HouseModel.ThreeRoomTwoHall, Orientation = Orientation.Southeast, Decoration = Fitment.Roughcast, SalePrice = 450, BrokerPhoneNumber = "13712345678", BrokerUserCode = "123456", Reg_Id = "111111", PropertyBookColor = "绿色", }; string json = model.ToJson(); json = "{\"HouseBackupInfo\":{\"Data\":\"" + DESHelper.Encrypt(json, "123456") + "\"},\"Id\":1381476266631331840,\"CreationDate\":\"2021-04-12T16:45:23.2095475+08:00\"}"; var cus = json.ToObject <HouseBackupInfo>(); _eventBus.Publish(new OperationHouseBackInfoEvent(cus)); }
/// <summary> /// 删除账号信息 /// </summary> /// <param name="username">要删除的用户名</param> /// <param name="server">游戏服务器</param> public void DeleteAccount(string username, int server) { if (accountList == null || username.Trim() == "") { return; } DESHelper des = new DESHelper(); for (int i = 0; i < accountList.Count; i++) { if (accountList[i].username == des.Encrypt(username)) { accountList.RemoveAt(i); break; } } if (!File.Exists("config.xml")) { return; } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("config.xml"); XmlNode xn = xmlDoc.SelectSingleNode("/Config/Accounts"); XmlNodeList xnl = xn.ChildNodes; if (xnl.Count <= 0) { return; } foreach (XmlNode acc in xnl) { XmlElement xe = (XmlElement)acc; if (xe.GetAttribute("Username") == des.Encrypt(username) && int.Parse(xe.GetAttribute("Server")) == server) { xe.ParentNode.RemoveChild(xe); break; } } xmlDoc.Save("config.xml"); }
public byte[] EnPwd_UTF8(List <byte[]> data) { try { return(DESHelper.Encrypt(data[0], data[1], data[2], System.Security.Cryptography.CipherMode.CBC, System.Security.Cryptography.PaddingMode.PKCS7, 8)); } catch (Exception) { return(Encoding.UTF8.GetBytes("")); } }
/// <summary> /// 设置当前登录用户 /// </summary> /// <param name="operatorModel"></param> public void AddCurrent(OperatorModel operatorModel) { if (LoginProvider == "Cookie") { WebHelper.WriteCookie(LoginUserKey, DESHelper.Encrypt(operatorModel.ToJson()), 60); } else { WebHelper.WriteSession(LoginUserKey, DESHelper.Encrypt(operatorModel.ToJson())); } }
public void EncrytpTest2() { var key = CryptoHelper.GenerateKey("*****@*****.**", 8); var iv = CryptoHelper.GenerateIv(8); var cipher = DESHelper.Encrypt("cszfp.com", key, iv); var clear = DESHelper.Decrypt(cipher, key, iv); Assert.AreEqual("cszfp.com", clear); }
public void EncryptTest() { var key = CryptoHelper.GenerateKey("*****@*****.**", 8); var strKey = Convert.ToBase64String(key); var cipher = DESHelper.Encrypt("cszfp.com", strKey); var clear = DESHelper.Decrypt(cipher, strKey); Assert.AreEqual("cszfp.com", clear); }
/// <summary> /// 生成Token /// </summary> /// <param name="content"></param> /// <returns></returns> public static string Build(string content) { string result = string.Empty; if (string.IsNullOrWhiteSpace(content)) { result = string.Empty; } else { var date = DateTime.Now; result = DESHelper.Encrypt(string.Join("|", new object[] { content, date.ToString("yyyy-MM-dd HH:mm:ss") })); } return(result); }
/// <summary> /// 3DES 加密 /// </summary> /// <param name="encryptString">待加密密文</param> /// <param name="encryptKey1">密匙1(长度必须为8位)</param> /// <param name="encryptKey2">密匙2(长度必须为8位)</param> /// <param name="encryptKey3">密匙3(长度必须为8位)</param> /// <returns></returns> public static string Encrypt(string encryptString, string encryptKey1, string encryptKey2, string encryptKey3) { string returnValue; try { returnValue = DESHelper.Encrypt(encryptString, encryptKey3); returnValue = DESHelper.Encrypt(returnValue, encryptKey2); returnValue = DESHelper.Encrypt(returnValue, encryptKey1); } catch (Exception ex) { throw ex; } return(returnValue); }
public void pubsh() { var model = new VerifyApplyResultDto() { HouseId = "SHQPS000000001", CertificateNumber = "青1234123456", VerifyApplyNumber = "123456123456", ProcessStatus = "核验通过", Reason = "", VerificationTime = DateTime.Now, FilePath = "SHQPS000000001.jpg", Reg_Id = "111111" }; string json = model.ToJson(); json = "{\"Data\":\"" + DESHelper.Encrypt(json, "123456") + "\"}"; var cus = json.ToObject <VerifyApplyResult>(); _eventBus.Publish("ex.system.verifyapplyresult.dev", "qu.system.housebackup.othersystem.dev", new OperationVerifyApplyResultEvent(cus)); }
public async Task <bool> Handle(OperationHouseBackInfoEvent @event) { try { Console.WriteLine("\n日志消费:" + @event.ToJson() + "\n\n"); var json = DESHelper.Decrypt(@event.HouseBackupInfo.Data, "cbs_5i5j_2021"); var model = json.ToObject <HouseBackupDto>(); ; var VerifyRes = new VerifyApplyResultDto() { HouseId = model.HouseId, CertificateNumber = model.CertificateNumber, VerifyApplyNumber = "123456123456", ProcessStatus = "核验通过", Reason = "", VerificationTime = DateTime.Now, FilePath = "SHPTS000068153.jpg", Reg_Id = "111111" }; json = VerifyRes.ToJson(); var encryptString = DESHelper.Encrypt(json, "cbs_5i5j_2021"); var res = new VerifyApplyResult() { Data = encryptString }; _eventBus.Publish("ex.gims.verifyapplyresult.dev", nameof(OperationVerifyApplyResultEvent), "qu.gims.verifyapplyresult.vplues.dev", res.ToJson()); } catch (Exception ex) { Console.WriteLine(ex); var re_json = @event.ToJson(); _eventBus.Publish("ex.vplues.housebackup.dev", nameof(OperationHouseBackInfoEvent), "qu.vplues.housebackup.gims.dev", re_json); } return(await Task.FromResult(true)); }
/// <summary> /// 保存账号信息 /// </summary> /// <param name="username">用户名</param> /// <param name="password">密码</param> /// <param name="server">游戏服务器</param> public void SaveAccounts(string username, string password, int server) { if (username.Trim() == "" || password == "") { return; } AccountList acc = new AccountList(); DESHelper des = new DESHelper(); acc.username = des.Encrypt(username); acc.password = des.Encrypt(password); acc.gameServer = server; XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration Declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); XmlNode rootNode = null; XmlElement accounts = null; if (!File.Exists("config.xml")) { xmlDoc.AppendChild(Declaration); xmlDoc.CreateElement("Config"); xmlDoc.AppendChild(rootNode); accounts = xmlDoc.CreateElement("Accounts"); rootNode.AppendChild(accounts); } else { xmlDoc.Load("config.xml"); accounts = (XmlElement)xmlDoc.SelectSingleNode("/Config/Accounts"); } bool found = false; if (accountList != null) { for (int i = 0; i < accountList.Count; i++) { if (accountList[i].username == acc.username && accountList[i].gameServer == acc.gameServer) { accountList[i] = acc; found = true; break; } } } if (found) { XmlNodeList xnl = accounts.ChildNodes; foreach (XmlNode account in xnl) { XmlElement xe = (XmlElement)account; if (xe.GetAttribute("Username") == des.Encrypt(username) && int.Parse(xe.GetAttribute("Server")) == server) { xe.SetAttribute("Password", des.Encrypt(password)); break; } } } else { XmlElement account = xmlDoc.CreateElement("Account"); accounts.AppendChild(account); account.SetAttribute("Username", acc.username); account.SetAttribute("Password", acc.password); account.SetAttribute("Server", acc.gameServer.ToString()); } accounts.SetAttribute("LastServer", server.ToString()); accounts.SetAttribute("LastAccount", acc.username); xmlDoc.Save("config.xml"); }