He hecho un programa con Visual C# Express 2008. Puedo enviar tramas desde Internet.
Cliente: Introduces un buuton1 y un textBox1.
Código
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Net; using System.Net.Sockets; namespace Client { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { udpClient.Connect(textBox1.Text, 60000); Byte[] sendBytes = Encoding.ASCII.GetBytes("Hola a todo el mundo..."); udpClient.Send(sendBytes, sendBytes.Length); } } }
Server:
Introduces un listBox1.
Código
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using System.Net.Sockets; using System.Net; namespace Server { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void serverThread() { while(true) { Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); listBox1.Items.Add(RemoteIpEndPoint.Address.ToString() + ":" + returnData.ToString()); } } private void Form1_Load(object sender, EventArgs e) { ThreadStart(serverThread)); thdUDPServer.Start(); } } }
Mi idea es que necesito encriptrar estas tramas que se envía a través de Internet para que los sniffer (husmeadores) no cojan libremente los datos enviados. Los datos puedes ser textos de un chat.
He encontrado algo aquí, pero no entiendo nada.
http://msdn.microsoft.com/es-es/library/system.security.cryptography.des.aspx
Código
private static void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV) { //Create the file streams to handle the input and output files. fout.SetLength(0); //Create variables to help with read and write. long rdlen = 0; //This is the total number of bytes written. long totlen = fin.Length; //This is the total length of the input file. int len; //This is the number of bytes to be written at a time. CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write); Console.WriteLine("Encrypting..."); //Read from the input file, then encrypt and write to the output file. while(rdlen < totlen) { len = fin.Read(bin, 0, 100); encStream.Write(bin, 0, len); rdlen = rdlen + len; Console.WriteLine("{0} bytes processed", rdlen); } encStream.Close(); fout.Close(); fin.Close(); }
http://msdn.microsoft.com/es-es/library/system.security.cryptography.aspx