I want to divide the integrated input I get from a TCP connection(in bytes) into several different byte arrays.I have a server and client. server that encrypts a message by 3DES and encrypts the key and IV by RSA.
Then it concatenates them together like this (plaintext + ciphertext + key + IV) and sends it to the client.
The client must read from bytes 0 to 20 and save it as a plaintext, then read from bytes 21 to 129 and save it as the key and so on. Any Ideas on how to implement it in C#? I'd appreciate your help.
void ReadFromTCPClientStream(IAsyncResult iar)
{
TcpClient tcpClient;
int nCountReadBytes = 0;
try
{
tcpc = (TcpClient)iar.AsyncState;
nCountReadBytes = tcpc.GetStream().EndRead(iar);
if(nCountReadBytes == 0)
{
printStatus("Client disconnected");
return;
}
readBuff = new byte[512];
tcpc.GetStream().BeginRead(readBuff, 0, readBuff.Length, ReadFromTCPClientStream, tcpClient);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
i want to split readbuff to multiple byte arrays as i said.
What I have tried:
I think with the foreach it can read from one byte to another byte and then store it.But I don't know exactly how?