BlowFish String Encryption

This is the root cause of all your problems, if I understand you correctly:

  • You can easily represent a string by a memory block
  • You cannot represent a memory block as string,

because in a memory block special characters can occur, like

  • ASCII(0) → terminates your string, even though the memory goes on
  • ASCII(>127) → unicode byte, only allows specific characters following the one (google UTF-8 or multibyte character)

Hence you need an encoding (e.g. base64 that @dave suggested), to represent all numbers in the encoded memory, or you simply save it as binary data.

What is important, that you always keep encoding and decoding symmetrical. A common mistake is to accidentally run encode or decode twice, which leads to gibberish.

Also make sure to use the encoding and decoding from the same package, if possible. There was e.g. a base64 encoding in the codebase, that was slightly different (see this Base64 thread…)

Whenever you call MemoryBlock::toString() (also when using the operator<<() ), it will assert, if there are invalid characters, and the chances are quite high, as you painfully found out already…

Hope that made the assert a little more clear