Cryp Data Sender : Crypto Connection « Network « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » Network » Crypto ConnectionScreenshots 
Cryp Data Sender

/*
C# Network Programming 
by Richard Blum

Publisher: Sybex 
ISBN: 0782141765
*/

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;
using System.Security;
using System.Security.Cryptography;
using System.Text;

public class CryptoDataSender
{
   private void SendData(NetworkStream strm, SerialEmployee emp)
   {
      IFormatter formatter = new SoapFormatter();
      MemoryStream memstrm = new MemoryStream();

      byte[] Key = {0x010x020x030x040x050x060x070x080x090x100x110x120x130x140x150x16};
      byte[] IV = {0x010x020x030x040x050x060x070x080x090x100x110x120x130x140x150x16};

      TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
      CryptoStream csw = new CryptoStream(memstrm, tdes.CreateEncryptor(Key, IV), CryptoStreamMode.Write);

      formatter.Serialize(csw, emp);
      csw.FlushFinalBlock();
      byte[] data = memstrm.GetBuffer();
      int memsize = (int)memstrm.Length;
      byte[] size = BitConverter.GetBytes(memsize);
      strm.Write(size, 04);
      strm.Write(data, 0(int)memsize);
      strm.Flush();
      csw.Close();
      memstrm.Close();
   }

   public CryptoDataSender()
   {
      SerialEmployee emp1 = new SerialEmployee();
      SerialEmployee emp2 = new SerialEmployee();

      emp1.EmployeeID = 1;
      emp1.LastName = "Blum";
      emp1.FirstName = "Katie Jane";
      emp1.YearsService = 12;
      emp1.Salary = 35000.50;

      emp2.EmployeeID = 2;
      emp2.LastName = "Blum";
      emp2.FirstName = "Jessica";
      emp2.YearsService = 9;
      emp2.Salary = 23700.30;

      TcpClient client = new TcpClient("127.0.0.1"9050);
      NetworkStream strm = client.GetStream();

      SendData(strm, emp1);
      SendData(strm, emp2);
      strm.Close();
      client.Close();
   }

   public static void Main()
   {
      CryptoDataSender cds = new CryptoDataSender();
   }
}


[Serializable]
public class SerialEmployee
{
   public int EmployeeID;
   public string LastName;
   public string FirstName;
   public int YearsService;
   public double Salary;

   public SerialEmployee()
   {
      EmployeeID = 0;
      LastName = null;
      FirstName = null;
      YearsService = 0;
      Salary = 0.0;
   }
}


           
       
Related examples in the same category
1. CryptoStream demo
2. Cryp Data Receiver
w__w_w_.j__av___a__2s___.__co_m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.