Base64 Encode & Decode Example in C#/CSharp

A simple Base64 Encode and Decode Example in C#/CSharp.

 

Base64 Encode Example in C#

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

 

 

Base64 Decode Example in C#

public static string Base64Decode(string base64EncodedData) {
  var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
  return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}