To convert from a .net string to a base 64, using UTF8 as the base encoding:
string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(text));
And to cancel the process:
string text = Encoding.UTF8.GetString(Convert.FromBase64String(base64));
You can absolutely skip step UTF8. However, UTF8 usually results in a lower payload, which is UTF16 and therefore I would recommend using UTF8 as the base encoding.
I'm not sure what you mean when you say that the user can enter UTF8 characters. The .net structure uses UTF16 as the encoding of the working string. The strings you use in .net are always encoded using UTF16. Perhaps you just mean that the text may contain characters other than ASCII.
source share