Sunday, October 30, 2011

How to convert string to Base64String, vice versa

You want to change stirng to base64string, vice versa, the following code is useful.

public static string ToBase64String(string s)

{

byte[] aby = UTF8Encoding.UTF8.GetBytes(s);

return Convert.ToBase64String(aby);

}

public static string FromBase64String(string s)

{

byte[] aby = Convert.FromBase64String(s);

return UTF8Encoding.UTF8.GetString(aby);

}


No comments:

Post a Comment