Skip to content

Instantly share code, notes, and snippets.

@PaulDMendoza
Created August 14, 2018 23:07
Show Gist options
  • Save PaulDMendoza/2b511c775fcd600076febc80782cac7a to your computer and use it in GitHub Desktop.
Save PaulDMendoza/2b511c775fcd600076febc80782cac7a to your computer and use it in GitHub Desktop.
SigParser Decoder Example
///<summary>
/// Decode Base64 encoded string with URL and Filename Safe Alphabet using UTF-8.
///</summary>
///<param name="str">Base64 code</param>
///<returns>The decoded string.</returns>
public static string DecodeBase64(string str)
{
if (str == null)
return str;
int padChars = (str.Length % 4) == 0 ? 0 : (4 - (str.Length % 4));
StringBuilder result = new StringBuilder(str, str.Length + padChars);
result.Append(String.Empty.PadRight(padChars, '='));
result.Replace('-', '+');
result.Replace('_', '/');
var data = Convert.FromBase64String(result.ToString());
string decodedString = Encoding.UTF8.GetString(data);
return decodedString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment