Encoding and Decoding Base64 strings in C#
Encode a string from Base64
Decode a Base64 encoded string
public static string EncodeTo64(string toEncode)
{
byte[] toEncodeAsBytes
= System.Text.Encoding.Unicode.GetBytes(toEncode);
string returnValue
= System.Convert.ToBase64String(toEncodeAsBytes);
return returnValue;
}
Decode a Base64 encoded string
public static string DecodeFrom64(string encodedData)
{
byte[] encodedDataAsBytes
= System.Convert.FromBase64String(encodedData);
string returnValue =
System.Text.Encoding.Unicode.GetString(encodedDataAsBytes);
return returnValue;
}
Comments
Post a Comment