Created
November 27, 2015 11:26
-
-
Save osya/fd2db3456b61844d1e9e to your computer and use it in GitHub Desktop.
Base64 C# #CSharp
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
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