Convert string to base64 string
A while back I came across the need to convert regular string text into a base64 string. .Net makes this fairly easy to do. I created a public static class and added two public static methods to encode/decode strings. Now they don't have to be static or public but I tend to make helper/utility classes that way. All of the classes being used are in the System and System.Text namespaces. /// <summary> /// Encodes the string to Base64. /// </summary> /// <param name="valueToEndcode">The value to endcode.</param> /// <returns>A base64 encoded string.</returns> public static string EncodeStringToBase64( string valueToEndcode ) { // encode the string into ascii byte array byte[] toEncodeAsBytes = ASCIIEncoding.ASCII.GetBytes( valueToEndcode ); // use the byte array to encode to a base64 string string returnValue = Convert.ToBase64String( toEncodeAsBytes ); // drop back the new encoded string value return returnValue; } /...