RC2 Encryption and Packet Delimiters

493 Views Asked by At

I am working on a client/server application and communication between the two is encrypted. I am using RC2 encryption because the client is embedded and CPU resources are limited. I am using the System.Security.Cryptography.RC2CryptoServiceProvider.CreateDecryptor/CreateEncryptor methods to create the encryption classes.

My problem stems from TCP's tendency to split up messages into multiple packets. Because the entire message may not arrive in one call of Socket.Receive(), I need to include a packet delimiter at the end of the outbound packet so the receiving end can tell where the packet ends (currently using 0x0D). However, the RC2 encryption ends up creating a 0x0D somewhere in the payload, causing the receiving end to interpret the packet as done. When it tries to decrypt this truncated packet, it fails.

Any advice on how this sort of thing is normally handled? Or even just a character that RC2 encryption is known NOT to produce that I can use as a delimiter?

1

There are 1 best solutions below

0
On BEST ANSWER

Used GregS's suggestion to prefix the encrypted packet with the length header, and put the packet delimiter after the encrypted packet for sanity checking. Thanks!