Created
June 9, 2023 10:51
-
-
Save jskeet/fb7282256223dce21314fafebb9fcf22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
string original = "{\"name\":\"John\", \"age\":30, \"car\":null}"; | |
string base64 = Base64Encode(original); | |
string decoded = Base64Decode(base64); | |
Console.WriteLine($"Original: {original}"); | |
Console.WriteLine($"Base64: {base64}"); | |
Console.WriteLine($"Decoded: {decoded}"); | |
string Base64Encode(string plainText) | |
{ | |
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); | |
return System.Convert.ToBase64String(plainTextBytes); | |
} | |
string Base64Decode(string base64EncodedData) | |
{ | |
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); | |
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment