using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;

using System.Security.Cryptography;

public class Client
{
    //Client liest Daten ein
    public static void Main(string[] args)
    {
        Console.WriteLine("Client");

        IPAddress ipadr = IPAddress.Parse("127.0.0.1");
        TcpListener tcpListener = new TcpListener(ipadr, 9000);
        tcpListener.Start();
        Socket socket = tcpListener.AcceptSocket();

        if (socket.Connected)
        {
            NetworkStream ns = new NetworkStream(socket);

            byte[] readBytes = new byte[10];

            UnicodeEncoding ue = new UnicodeEncoding();

            byte[] key = Convert.FromBase64String("HvUPIbS3UM4HSrzGORLmTFAf359ay+mI");
            byte[] iv = Convert.FromBase64String("RC0TQxaU5f8=");

            TripleDES tdes = TripleDES.Create();
            CryptoStream cs =
               new CryptoStream(ns, tdes.CreateDecryptor(key, iv), CryptoStreamMode.Read);
            cs.Read(readBytes, 0, 10);

            string receive = Encoding.Unicode.GetString(readBytes);

            cs.Close();

            Console.WriteLine(receive);
        }
        socket.Close();
        Console.ReadLine();
    }
}
