Does a binary encrypted string could contain a ‘space’ or ‘carriage return’? What’s the best way to put a separator between two encrypted byte[] arrays?
Does a binary encrypted string could contain a ‘space’ or ‘carriage return’? What’s the
Share
There’s no such concept in binary data, generally. You could define a particular byte (or byte sequence) to be a separator, but then you’d have to work out escaping rules in case that data occurred naturally.
It’s generally a better idea to include a length prefix – so if you had multiple values you might have:
(where
terminatoris a length of -1 or some equally invalid value).Aside from anything else, this makes it much easier to read the data than having to scan it for separators. You can read just the data for the next chunk (or value, or whatever) without accidentally reading into the next value… so you can then just pass the stream on to whatever needs to read the next length/value pair.