Skip to content

Instantly share code, notes, and snippets.

@ianaya89
Created January 20, 2015 20:12
Show Gist options
  • Save ianaya89/29d158bdb92f4d623462 to your computer and use it in GitHub Desktop.
Save ianaya89/29d158bdb92f4d623462 to your computer and use it in GitHub Desktop.
Base64 Encode and Decode Methods
public static string EncodeTo64(string toEncode)
{
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
return returnValue;
}
public static string DecodeFrom64(string encodedData)
{
byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
string returnValue = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
return returnValue;
}
public void Test(){
string myData = "Here is a string to encode.";
string myDataEncoded = EncodeTo64(myData);
Console.WriteLine(myDataEncoded);
string myDataUnencoded = DecodeFrom64(myDataEncoded);
Console.WriteLine(myDataUnencoded);
Console.ReadLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment