Exemple #1
0
        public void takeClient()
        {
            NetworkStream stream = client.GetStream();
            StreamReader  reader = new StreamReader(stream);
            StreamWriter  writer = new StreamWriter(stream);

            writer.WriteLine("Client Connected");

            writer.Flush();
            String line = null;

            while ((line = reader.ReadLine()).Length != 0)
            {
                string keyencrypted = null;
                string IV           = null;
                string filencrypted = null;
                keyencrypted = reader.ReadLine(); // received encrypted key
                IV           = reader.ReadLine();
                filencrypted = reader.ReadLine(); // received encrypted file
                byte[] receiveFile = Convert.FromBase64String(filencrypted);
                byte[] sessionkey  = Convert.FromBase64String(keyencrypted);
                byte[] sessioniv   = Convert.FromBase64String(IV);

                string IVfile  = asy_crypt.DecryptData(sessioniv, "PrivateKey.xml");
                string keyfile = asy_crypt.DecryptData(sessionkey, "PrivateKey.xml");

                writer.WriteLine("received");
                sessionkey = Convert.FromBase64String(keyfile);
                byte[] file_decrypted = sy_C.dycryptFile(receiveFile, sessionkey, Convert.FromBase64String(IVfile));
                Server.GUI.show("file recerived");
                File.WriteAllBytes(line, file_decrypted);
                Server.GUI.show("Recived from client" + ((IPEndPoint)client.Client.RemoteEndPoint).Port.ToString() + "  :" + line);



                writer.Flush();
            }
            Server.GUI.show("Client " + ((IPEndPoint)client.Client.RemoteEndPoint).Port.ToString() + "disconnected");
            client.Close();
        }
Exemple #2
0
    protected void DecryptCommand_Click(object sender, EventArgs e)
    {
        // Check for encryption key
        if (!File.Exists(KeyFileName))
        {
            Response.Write("Missing encryption key. Please generate key!");
        }

        try
        {
            byte[] data = Convert.FromBase64String(EncryptedDataText.Text);
            ClearDataText.Text = AsymmetricEncryptionUtility.DecryptData(data, KeyFileName);
        }
        catch
        {
            Response.Write("Unable to decrypt data!");
        }
    }