[Botan-devel] Sending raw, unencoded data over a network

Jack Lloyd lloyd at randombit.net
Mon Apr 13 12:41:58 EDT 2009

On Mon, Apr 13, 2009 at 10:50:45AM -0400, Z. S. O. wrote:
> I'm making a program that encrypts something using Botan and sends it
> somewhere over UDP. The problem is that, if the encrypted data is not
> encoded in something like Base64, the recipient won't always get all the
> data. My theory is that sometimes there is a null byte in the encrypted
> data, so when the recipient tries to copy it to a char array it gets cut off
> early. Encoding the encrypted data in Base64 solves the problem, but it
> dramatically increases the size of the data so I don't prefer it. Is there a
> solution to this?

This seems expected - using \0 terminators with arbitrary binary data
usually leads to trouble. The conventional technique would be to
include an explict length field at the beginning of the packet, and
always copy exactly this amount the buffer. However UDP includes the
length field in the packet header already, so there actually isn't any
need to do that - recv or recvmsg will return the length of the packet
when you read it out from the socket buffer. Hope this helps.


More information about the botan-devel mailing list