String Extension functions: Convert strings to and from base64 string

Posted by Blessyjees under C# category on | Points: 40 | Views : 3671
We can write strinf extension function to convert string to base64string and viceversa.

String to Base64String
   public static string ToBase64String(this string value)
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(value);
return System.Convert.ToBase64String(toEncodeAsBytes);

string from Base64String
public static string FromBase64String(this string value)
byte[] encodedDataAsBytes = System.Convert.FromBase64String(value);
return System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);

Comments or Responses

Login to post response