elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  cifrar tramas de bytes
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: cifrar tramas de bytes  (Leído 3,367 veces)
Meta


Desconectado Desconectado

Mensajes: 3.439



Ver Perfil WWW
cifrar tramas de bytes
« en: 20 Mayo 2009, 21:02 pm »

Buenas:
He hecho un programa con Visual C# Express 2008. Puedo enviar tramas desde Internet.
Cliente: Introduces un buuton1 y un textBox1.
Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Net;
  11. using System.Net.Sockets;
  12.  
  13. namespace Client
  14. {
  15.    public partial class Form1 : Form
  16.    {
  17.        public Form1()
  18.        {
  19.            InitializeComponent();
  20.        }
  21.  
  22.        private void button1_Click(object sender, EventArgs e)
  23.        {
  24.            UdpClient udpClient = new UdpClient();
  25.            udpClient.Connect(textBox1.Text, 60000);
  26.            Byte[] sendBytes = Encoding.ASCII.GetBytes("Hola a todo el mundo...");
  27.            udpClient.Send(sendBytes, sendBytes.Length);
  28.        }
  29.    }
  30. }
  31.  

Server:
Introduces un listBox1.
Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Threading;
  10. using System.Net.Sockets;
  11. using System.Net;
  12.  
  13. namespace Server
  14. {
  15.    public partial class Form1 : Form
  16.    {
  17.        public Form1()
  18.        {
  19.            InitializeComponent();
  20.        }
  21.  
  22.        public void serverThread()
  23.        {
  24.            UdpClient udpClient = new UdpClient(60000);
  25.            while(true)
  26.            {
  27.                IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
  28.                Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
  29.                string returnData = Encoding.ASCII.GetString(receiveBytes);
  30.                 listBox1.Items.Add(RemoteIpEndPoint.Address.ToString() +
  31.                    ":" + returnData.ToString());
  32.            }
  33.        }
  34.  
  35.        private void Form1_Load(object sender, EventArgs e)
  36.        {
  37.            Thread thdUDPServer = new Thread(new
  38.            ThreadStart(serverThread));
  39.            thdUDPServer.Start();
  40.        }
  41.    }
  42. }
  43.  

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
  1. private static void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV)
  2. {    
  3.     //Create the file streams to handle the input and output files.
  4.     FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
  5.     FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
  6.     fout.SetLength(0);
  7.  
  8.     //Create variables to help with read and write.
  9.     byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
  10.     long rdlen = 0;              //This is the total number of bytes written.
  11.     long totlen = fin.Length;    //This is the total length of the input file.
  12.     int len;                     //This is the number of bytes to be written at a time.
  13.  
  14.     DES des = new DESCryptoServiceProvider();          
  15.     CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);
  16.  
  17.     Console.WriteLine("Encrypting...");
  18.  
  19.     //Read from the input file, then encrypt and write to the output file.
  20.     while(rdlen < totlen)
  21.     {
  22.         len = fin.Read(bin, 0, 100);
  23.         encStream.Write(bin, 0, len);
  24.         rdlen = rdlen + len;
  25.         Console.WriteLine("{0} bytes processed", rdlen);
  26.     }
  27.  
  28.     encStream.Close();  
  29.     fout.Close();
  30.     fin.Close();                  
  31. }
  32.  

http://msdn.microsoft.com/es-es/library/system.security.cryptography.aspx


En línea

MazarD
Colaborador
***
Desconectado Desconectado

Mensajes: 885


mazard.info


Ver Perfil WWW
Re: cifrar tramas de bytes
« Respuesta #1 en: 20 Mayo 2009, 21:40 pm »

Qué es exactamente lo que no entiendes?

Para empezar es bueno tener una visión general de la cifrado que vas a utilizar, en el caso de DES es bastante importante:
http://es.wikipedia.org/wiki/Data_Encryption_Standard

Luego la función que has pegado simplemente recibe ruta de entrada, ruta de salida, clave y te genera el archivo cifrado, puedes probarlo llamandola así por ejemplo:

Código
  1.            byte[] llave= new byte[8]{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};
  2.            byte[] iv= new byte[8] {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};
  3.            EncryptData("c:\\archivoAencriptar.txt", "c:\\archivoAgenerar.txt", llave, iv);
  4.  

:P

Para descifrar, en la función de ejemplo que tienes, deberías cambiar createencryptor por createdecryptor y hacer que el stream fuera de lectura.
Bueno si tienes alguna duda concreta, comentalo.

Saludos!


En línea

-Learn as if you were to live forever, live as if you were to die tomorrow-

http://www.mazard.info
irc://irc.freenode.org/elhacker.net
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Comunicación por red, capturar tramas completas
Programación General
zonahurbana 3 2,218 Último mensaje 1 Junio 2015, 19:01 pm
por engel lex
Enviar tramas de bytes en C++/CLR
.NET (C#, VB.NET, ASP)
Meta 1 1,841 Último mensaje 15 Febrero 2016, 22:47 pm
por Meta
Detectar tramas de bytes
.NET (C#, VB.NET, ASP)
Meta 0 1,749 Último mensaje 15 Noviembre 2023, 20:53 pm
por Meta
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines