Created
April 14, 2015 11:41
-
-
Save ivanrad/b0ba178ef590974ddfce to your computer and use it in GitHub Desktop.
decode from URL-safe base64
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
public static byte[] FromUrlSafeBase64(string input) | |
{ | |
// restore padding, if padding trimmed | |
int padding = 4 - (input.Length%4); | |
input = input.PadRight(padding, '='); | |
char[] buf = Array.ConvertAll(Encoding.UTF8.GetBytes(input), c => (char) c); | |
for (int i = 0; i < buf.Length; ++i) | |
switch (buf[i]) { | |
case '-': | |
buf[i] = '+'; | |
break; | |
case '_': | |
buf[i] = '/'; | |
break; | |
} | |
return Convert.FromBase64CharArray(buf, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment