Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


C#
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?
Posted
Updated 4-Aug-19 10:37am
v3
Comments
[no name] 4-Aug-19 16:12pm    
readBuff = new byte[512];

Chunk thru that.

1 solution

 
Share this answer
 
v2
Comments
Member 14179902 4-Aug-19 16:35pm    
Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900