Encoding string to Base64 / UTF8
Sometimes you need to convert strings to Base64, for example in security components. The function below does this:
public string stringToBase64(string s)
{
try
{
byte[] bytes = new byte[s.Length];
bytes = System.Text.Encoding.UTF8.GetBytes(s);
return Convert.ToBase64String(bytes);
}
catch (Exception e)
{
throw new Exception("stringToBase64 error: " + e.Message);
}
}