//Отправка сообщений private void SendMessage() { Socket socket = new Socket(IpServer.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { socket.Connect(IpServer, port); label4.Text = "Подключение с сервером установлено"; Send.Enabled = true; byte[] key = Encoding.UTF8.GetBytes("Key"); RC4 encoder = new RC4(key); string message = DateTime.Now.ToString("[HH:mm:ss]") + Login + ": " + richTextBox1.Text; byte[] encryptBytes = Encoding.UTF8.GetBytes(message); byte[] result = encoder.Encode(encryptBytes, encryptBytes.Length); int SendMsg = socket.Send(result); byte[] buffer = new byte[1024]; int bytesRec = socket.Receive(buffer); RC4 decoder = new RC4(key); byte[] decryptedBytes = decoder.Decode(result, result.Length); string message1 = Encoding.UTF8.GetString(decryptedBytes); richTextBox2.Text = richTextBox2.Text + message1 + "\r\n"; using (var sw = File.AppendText(@"Log_chat.txt")) { sw.WriteLine(message + "\r\n"); } richTextBox1.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Cipher(string inputFile) { byte[] bytes = File.ReadAllBytes(inputFile); RC4 encoder = new RC4(key); byte[] result = encoder.Encode(bytes, bytes.Length); File.WriteAllBytes(inputFile, result); }
public async Task <ActionResult <string> > Post(IFormFile message, IFormFile key) { byte[] fileBytesMessage, fileBytesKey; if (message == null || key == null) { ModelState.AddModelError("Error", "Некорректные параметры"); return(BadRequest(ModelState)); } if (message.Length > 0 && key.Length > 0) { using (var ms = new MemoryStream()) { message.CopyTo(ms); fileBytesMessage = ms.ToArray(); } using (var ms = new MemoryStream()) { key.CopyTo(ms); fileBytesKey = ms.ToArray(); } var rc4 = new RC4(fileBytesKey); var result = rc4.Encode(fileBytesMessage); var path = "(rc4)" + message.FileName; using (var fs = System.IO.File.Create(_environment.WebRootPath + "/" + path)) { fs.Write(result, 0, result.Count()); fs.Flush(); return(path); } } else { return(BadRequest()); } }
public void saveAssetsSeparately(string projectPath, bool locked) { if (Assets.items != null) { List<AssetList> packages = new List<AssetList>(); for (int i = 0; i < Assets.items.Count; i++) { Asset asset = Assets.items[i]; AssetList package = findPackage(packages, asset.package); if (package == null) { package = new AssetList(); package.name = asset.package; packages.Add(package); } if (package.name == null) package.name = "Unnamed"; package.Add(asset); } for (int i = 0; i < packages.Count; i++) { string name = Path.Combine(projectPath, packages[i].name.Replace(" ", "_") + ".pak"); Serialization.serialize(name, packages[i]); if (locked) { byte[] key = ByteConverter.GetBytes("dfy3hfi3789y478yhge7y578yrhgiudhr8967498u839udhkjghjk"); RC4 rc4 = new RC4(key); byte[] file = File.ReadAllBytes(name); file = rc4.Encode(file, file.Length); File.WriteAllBytes(name, file); } } } }