Created
August 14, 2018 23:07
-
-
Save PaulDMendoza/2b511c775fcd600076febc80782cac7a to your computer and use it in GitHub Desktop.
SigParser Decoder Example
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
///<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