Clearly you need to pad the plaintext before encrypting it. Pad
it to some fixed size – optimally this should also be a multiple
of the block size (16 bytes are nowadays standard for block
ciphers), so you don't have to pad again for encryption. Make
the padding removable. There are several methods of doing this:
If you now that your message can't contain certain bytes or byte
sequences, you can use a separator. A zero byte works if your
plaintext contains only printable text in ASCII or some
compatible encoding. This will not work if the plaintext can
contain arbitrary binary data, if you don't escape it first. Not
generally recommended. If your message has a certain internal
structure which tells you when it is finished, you don't need a
separator – simply parse it and stop when the message ends. Here
you'll have to pay attention to buffer overruns and similar. Not
generally recommended. Encode the length of the message at the
start of the message. (Of course, this only works when you have
the whole message