private void padding4ToolStripMenuItem_Click(object sender, EventArgs e) { CrypterAES.setPadding(System.Security.Cryptography.PaddingMode.Zeros); this.padding1ToolStripMenuItem.Checked = false; this.padding2ToolStripMenuItem.Checked = false; this.padding3ToolStripMenuItem.Checked = false; }
private void Mode5ToolStripMenuItem_Click(object sender, EventArgs e) { CrypterAES.setMode(System.Security.Cryptography.CipherMode.OFB); this.Mode1ToolStripMenuItem.Checked = false; this.Mode2ToolStripMenuItem.Checked = false; this.Mode3ToolStripMenuItem.Checked = false; this.Mode4ToolStripMenuItem.Checked = false; }
public User(string Name, String HostName, int avatar, Client client) { this.Name = Name; this.HostName = HostName; this.avatarNumber = avatar; this.client = client; this.contact = null; this.message = null; this.lastMessageY = 0; this.crypt = null; }
public User() { throw new Exception("empity user"); this.Name = null; this.HostName = null; this.avatarNumber = 0; this.client = null; this.contact = null; this.message = null; this.lastMessageY = 0; this.crypt = null; }
public void setUser(User newUser) { if (this.user.Name.Equals(newUser.Name) && this.user.HostName.ToLower().Equals(newUser.HostName.ToLower())) { this.user = newUser; this.user.setClient(this); this.rsa = null; this.perhaps = null; this.uploadFile = new List <AddFile>(); this.quenSend = new List <byte[]>(); this.uploadFileThread = null; this.sendThread = null; this.stopSendThread = false; } }
public Client(TcpClient tcpClient, Chat Form = null) { this.tcp = tcpClient; this.stream = tcpClient.GetStream(); this.form = Form; this.startdownloadFile = new List <AddFile>(); this.downloadFile = new List <AddFile>(); this.uploadFile = new List <AddFile>(); this.quenSend = new List <byte[]>(); this.downloadFileThread = null; this.uploadFileThread = null; this.sendThread = null; this.stopSendThread = false; this.perhaps = null; this.rsa = null; }
static public void SaveMe(User me) { Storage.me = me; Storage.key = me.Name.GetHashCode(); if (!Directory.Exists(DefaultData)) { Directory.CreateDirectory(DefaultData); } try{ var output = new BinaryWriter(File.Open(DefaultData + "/" + DefaultUserData, FileMode.Create)); byte[] mess = Encoding.UTF8.GetBytes(InFileName + me.Name + "\n"); for (int i = 0; i < mess.Length; i++) { Storage.WriteByte(output, mess[i]); } mess = Encoding.UTF8.GetBytes(InFileHostName + me.HostName + "\n"); for (int i = 0; i < mess.Length; i++) { Storage.WriteByte(output, mess[i]); } mess = Encoding.UTF8.GetBytes(InFileAatarNumber + me.avatarNumber + "\n"); for (int i = 0; i < mess.Length; i++) { Storage.WriteByte(output, mess[i]); } mess = Encoding.UTF8.GetBytes(CrypterAES.getMode() + InFileCryptSeparator + CrypterAES.getPadding() + InFileCryptSeparator); mess = Program.ConcatByte(mess, me.crypt.getKey()); mess = Program.ConcatByte(mess, Encoding.UTF8.GetBytes(InFileCryptSeparator)); mess = Program.ConcatByte(mess, me.crypt.getIV()); mess = Program.ConcatByte(mess, Encoding.UTF8.GetBytes(InFileCrypt + "\n")); for (int i = 0; i < mess.Length; i++) { Storage.WriteByte(output, mess[i]); } output.Close(); }catch { } }
private void toolStripMenuItem4_Click(object sender, EventArgs e) { CrypterAES.setKeySize(256); this.toolStripMenuItem3.Checked = false; this.toolStripMenuItem2.Checked = false; }
public void update(User u) { this.avatarNumber = u.avatarNumber; this.client = u.client; this.crypt = null; }
private void OnMessage(byte[] Message, bool isRsa = false) { byte[][] mess = Program.Split(Message, Encoding.UTF8.GetBytes(Separator), true); if (mess.Length == 0) { return; } //this.form.SendToFormMessage(((this.perhaps != null) ? "aes_per" : "null") + ((!isRsa) ? "aes_per" : "null")); //for(int i = 0; i<mess.Length; i++) // this.form.SendToFormMessage("sr4.M: " + i + ": " + mess[i].Length + ": " + Encoding.UTF8.GetString(mess[i])); string head = Encoding.UTF8.GetString(mess[0]); switch (head) { case HeadFileDop: { if ((mess.Length == 5) && (this.user != null)) { string name = Encoding.UTF8.GetString(mess[1]), newName = Encoding.UTF8.GetString(mess[2]), blockNumber = Encoding.UTF8.GetString(mess[3]), blockSize = Encoding.UTF8.GetString(mess[4]); ulong number = Convert.ToUInt64(blockNumber); int size = Convert.ToInt32(blockSize); try { byte[] block = Storage.getBlockFile(name, size, number); int hash = Program.HechBytes(block); string header = HeadFile + Separator + name + Separator + newName + Separator + Convert.ToString(number) + Separator + Convert.ToString(hash) + Separator; byte[] buffer = Encoding.UTF8.GetBytes(header); this.Send(Program.ConcatByte(buffer, block)); this.form.SendToFormMessage("Dop file block: " + number); } catch (Exception e) { this.form.SendToFormMessage("Dop file block eror: " + e.Message + "\n" + e.StackTrace); } } break; } case HeadFile: { if ((mess.Length == 4) && (this.user != null)) { string name = Encoding.UTF8.GetString(mess[1]), newName = Encoding.UTF8.GetString(mess[2]), Error = Encoding.UTF8.GetString(mess[3]); var file = new AddFile(this.user, name, 0, 0, newName); file.setError(Error); this.form.downloadError(file); } if ((mess.Length == 5) && (this.user != null)) { string name = Encoding.UTF8.GetString(mess[1]), newName = Encoding.UTF8.GetString(mess[2]), blockSize = Encoding.UTF8.GetString(mess[3]), countBlock = Encoding.UTF8.GetString(mess[4]); var file = Storage.getAddFile(name, newName, Convert.ToInt32(blockSize), Convert.ToUInt64(countBlock)); if (file != null) { this.startUpload(file); } else { this.Send(false, HeadFile, name, newName, "file not found"); } } else if ((mess.Length == 6) && (this.user != null)) { this.Send(Client.Good); string name = Encoding.UTF8.GetString(mess[1]), newName = Encoding.UTF8.GetString(mess[2]); ulong blockNumber = Convert.ToUInt64(Encoding.UTF8.GetString(mess[3])); AddFile file = null; foreach (var i in this.downloadFile) { if (i.getNewName() == newName) { file = i; break; } } if (file != null) { if (mess[5].Length > file.getBlockSize()) { System.Array.Resize(ref mess[5], file.getBlockSize()); } if (blockNumber == file.getCountBlock() - 1 && file.getSize() % (ulong)file.getBlockSize() != 0) { System.Array.Resize(ref mess[5], (int)(file.getSize() % (ulong)file.getBlockSize())); } int hash2 = Program.HechBytes(mess[5]); if (Convert.ToInt32(Encoding.UTF8.GetString(mess[4])) == hash2) { try { Storage.setBlockFile(file.getNewName(), file.getBlockSize(), blockNumber, mess[5]); file.flagBlock[blockNumber] = 1; if (blockNumber > 100 && blockNumber % (file.getCountBlock() / 100) == 0) { if (file.isSave) { Storage.saveStatistic(blockNumber / (file.getCountBlock() / 100)); } this.form.UpdateDownloadInfo(file); this.form.SendToFormMessage("download: " + blockNumber / (file.getCountBlock() / 100) + "%"); } } catch (Exception e) { this.form.SendToFormMessage("download error: " + e.StackTrace); } } if (blockNumber == file.getCountBlock() - 1) { this.finishDownload(file); } } } break; } case HeadAddFile: { if ((mess.Length == 5) && (this.user != null)) { string name = Encoding.UTF8.GetString(mess[1]), size = Encoding.UTF8.GetString(mess[2]), time = Encoding.UTF8.GetString(mess[4]); string newName = Storage.getNewName(name); bool isPrivate = Convert.ToBoolean(Encoding.UTF8.GetString(mess[3])); var file = new AddFile(this.user, name, Convert.ToUInt64(size), Storage.getBlockSize(), Convert.ToDateTime(time), newName); file.isPrivate = isPrivate; this.form.SendToFormMessage(file); } break; } case HeadMessage: { if ((mess.Length != 4) && (this.user.client != null)) { break; } string text = Encoding.UTF8.GetString(mess[2]), time = Encoding.UTF8.GetString(mess[3]); bool isPrivate = Convert.ToBoolean(Encoding.UTF8.GetString(mess[1])); MESSAGE newMessage = new MESSAGE(this.user, Server.me, text, Convert.ToDateTime(time), isPrivate); this.form.SendToFormMessage(newMessage); break; } case HeadUser: { if (mess.Length == 3) { string HostName = Dns.GetHostEntry(((IPEndPoint)this.tcp.Client.RemoteEndPoint).Address).HostName; string name = Encoding.UTF8.GetString(mess[1]); string avatar = Encoding.UTF8.GetString(mess[2]); if (this.user == null) { this.user = new User(name, HostName, System.Convert.ToInt32(avatar), this); } else { this.user.update(System.Convert.ToInt32(avatar)); } this.form.SendToFormMessage("sr4.User"); Storage.SaveContact(this.user); this.form.OnConnect(this.user); } else { this.form.SendToFormMessage("sr4.NOT_USER"); } break; } case IfHaveServer: { this.Send(YesItIsServer); if (this.user == null) { this.Send(GetUserPliace); } break; } case YesItIsServer: { if (this.user == null) { this.Send(GetUserPliace); } break; } case GetUserPliace: { while (true) { if (Server.me != null) { this.Send(Server.me); break; } else { Thread.Sleep(200); } } break; } case EndSeans: { this.OnError(new Exception("Cancel")); break; } case GetSecretKey: { if (mess.Length == 2) { mess[1] = Program.SubBytes(mess[1], 0, 148); this.form.SendToFormMessage("Create Secret Data:" + mess[1].Length); this.form.SendToFormMessage("SecretKey: " + Program.HechBytes(mess[1])); rsa = new CrypterRSA(mess[1]); var aes = new CrypterAES(); byte[] message = new byte[0] { }; message = Program.ConcatByte(message, Encoding.UTF8.GetBytes(HeadSecret + Separator + CrypterAES.getMode() + Separator + CrypterAES.getPadding() + Separator)); message = Program.ConcatByte(message, aes.getKey()); message = Program.ConcatByte(message, Encoding.UTF8.GetBytes(Separator)); message = Program.ConcatByte(message, aes.getIV()); this.perhaps = aes; this.Send(rsa.Coder(message)); this.form.SendToFormMessage("hech: " + aes.GetHashCode()); } break; } case HeadSecret: { if (mess.Length == 5) { this.form.SendToFormMessage("Create Secret Line"); this.user.crypt = new CrypterAES(Convert.ToInt32(Encoding.UTF8.GetString(mess[1])), Convert.ToInt32(Encoding.UTF8.GetString(mess[2])), mess[3], mess[4]); this.rsa = null; this.Send(true, HeadSecret, Client.Good); this.form.SendToFormMessage("hech: " + this.user.crypt.GetHashCode()); } else if (mess.Length == 2) { this.form.SendToFormMessage("1: " + Encoding.UTF8.GetString(mess[1]) + " 2: " + (string)Client.Good); if (Encoding.UTF8.GetString(mess[1]) == Client.Good || true) { this.user.crypt = this.perhaps; this.perhaps = null; this.form.SendToFormMessage("secret good"); } } break; } default: { if (this.perhaps != null && !isRsa) { try { this.OnMessage(this.perhaps.DecoderBytes(Message), true); } catch (Exception e) { this.form.SendToFormMessage("eror pizdaaaaaaaaaaa: " + e.Message + "\n" + e.StackTrace); } } if (this.rsa != null && !isRsa && this.rsa.isPrivate) { try { this.OnMessage(this.rsa.Decoder(Message), true); } catch { return; } } break; } } }