Created
January 20, 2015 20:12
-
-
Save ianaya89/29d158bdb92f4d623462 to your computer and use it in GitHub Desktop.
Base64 Encode and Decode Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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