I want to encrypt what I send to a client on a server (not necessarily going for safety, just to prevent someone from easily seeing the data on something like Wireshark).
I’m looking for an algorithm where the result is still a NULL terminated string but can be decrypted back into a utf-8 string quite quickly and easily. The networking library I’m using only lets me send NULL terminated strings to clients, that is why. I’m using a UDP library with reliable packets.
What are some algorithms that could do this sort of thing?
Thanks
Xor all bytes with some value (or another string).
Before sending data, replace all ‘\0’ characters with 0xff 0xfe and all 0xff with 0xff 0xff. (you could use other values, obviously)
When receiving the data, reverse the process – replace 0xff 0xff with 0xff and oxff 0xfe with 0. then xor with key.
Alternatively you could base64-encode encrypted data to take care of
\0characters.