I’m trying to implement a requirement in our system that all strings be trimmed before going into the database. There is a layer in our system where I could handle this in one place, but I’m concerned that I might break encrypted strings if I do.
I know the encryption produces some non-alphanumeric characters, but are these limited to non-whitespace?
Most encryption algorithms – including Rijndael – work on binary data, not text. There’s no concept of a space (or a non-alphanumeric character) within binary data.
If you must store encrypted data as text, you’ll need to convert it from the binary data (e.g. a byte array) into text first. One simple way of doing that is to use Base64 (e.g.
Convert.ToBase64String(data)) – and Base64 never includes spaces using the standard codabet.So to summarize
Encoding.UTF8, as the encrypted data is not UTF-8-encoded text.