Skip to content

Instantly share code, notes, and snippets.

@tig
Created February 1, 2012 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tig/1715940 to your computer and use it in GitHub Desktop.
Save tig/1715940 to your computer and use it in GitHub Desktop.
Base64 conversion
public static string ToBase64(string encode) {
Byte[] btByteArray = null;
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
btByteArray = encoding.GetBytes(encode);
string sResult = System.Convert.ToBase64String(btByteArray, 0, btByteArray.Length);
sResult = sResult.Replace("+", "-").Replace("/", "_");
return sResult;
}
public static string FromBase64(string decode) {
decode = decode.Replace("-", "+").Replace("_", "/");
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetString(Convert.FromBase64String(decode));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment