Skip to content

Instantly share code, notes, and snippets.

@osya
Created November 27, 2015 11:26
Show Gist options
  • Save osya/fd2db3456b61844d1e9e to your computer and use it in GitHub Desktop.
Save osya/fd2db3456b61844d1e9e to your computer and use it in GitHub Desktop.
Base64 C# #CSharp
static byte[] AnotherDecode64(string base64Decoded)
{
string temp = base64Decoded.TrimEnd('=');
int asciiChars = temp.Length - temp.Count(c => Char.IsWhiteSpace(c));
switch (asciiChars % 4)
{
case 1:
//This would always produce an exception!!
//Regardless what (or what not) you attach to your string!
//Better would be some kind of throw new Exception()
return new byte[0];
case 0:
asciiChars = 0;
break;
case 2:
asciiChars = 2;
break;
case 3:
asciiChars = 1;
break;
}
temp += new String('=', asciiChars);
return Convert.FromBase64String(temp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment