Skip to main content

C# extension method to base64 encode a string.

public static string Base64Encode(this string s)
{
    var bytes = System.Text.Encoding.UTF8.GetBytes(s);
    return System.Convert.ToBase64String(bytes);
}