Skip to content

Instantly share code, notes, and snippets.

@ivanrad
Created April 14, 2015 11:41
Show Gist options
  • Save ivanrad/b0ba178ef590974ddfce to your computer and use it in GitHub Desktop.
Save ivanrad/b0ba178ef590974ddfce to your computer and use it in GitHub Desktop.
decode from URL-safe base64
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