public void NetworkSendInfo(NetworkStream stream, DIFFIE_HELMAN aes) { string hierarhy = GetInfo(); //Массив стрингов byte[] arr = new byte[hierarhy.LongCount()]; //Длина сериализованной строки arr = Encoding.Default.GetBytes(hierarhy); //Конвертируем в байты arr = aes.Encrypt(arr); // Шифруем FileProtocolReader.Write(arr, stream); }
public void KeysExchange(TcpClient client, NetworkStream networkStream, DIFFIE_HELMAN aes) { //Отправляем свой ключ FileProtocolReader.Write(aes.PublicKey, networkStream); FileProtocolReader.Write(aes.IV, networkStream); while (client.Connected) { if (networkStream.DataAvailable) { byte[] client_key = null; FileProtocolReader.Read(ref client_key, networkStream); aes.CreateSecretKey(client_key); return; } } }
public void SecurityLoadAndSave(string file_name, NetworkStream networkStream, byte[] key, DIFFIE_HELMAN aes) { using (stream = new FileStream(file_name, FileMode.CreateNew)) { /*networkStream.Read(file_length, 0, file_length.Length); //Считываем длину данных в потоке long length = BitConverter.ToInt64(file_length, 0); //Переводим длину*/ byte[] file_data = null; FileProtocolReader.Read(ref file_data,networkStream); file_data = aes.Decript(file_data); this.buf = StreamEncryptor.Encrypt(file_data, key); //Шифруем потоковым шифратором stream.Write(buf, 0, buf.Length); //Записываем данные в файл /*int read = 0; while (networkStream.DataAvailable) { read = networkStream.Read(this.buf, 0, buf.Length); //Считываем данные из сетевого потока aes.Decript(this.buf); //Дешифруем данные из сети this.buf = StreamEncryptor.Encrypt(this.buf,key); //Шифруем потоковым шифратором stream.Write(buf, 0, read); //Записываем данные в файл length -= read; }*/ } }