BCrypt.Net.BCrypt.DecodeBase64 C# (CSharp) Method

DecodeBase64() private static method

Decode a string encoded using bcrypt's base64 scheme to a byte array. Note that this is *not* compatible with the standard MIME-base64 encoding.
Thrown when one or more arguments have unsupported or /// illegal values.
private static DecodeBase64 ( string encodedstring, int maximumBytes ) : byte[]
encodedstring string The string to decode.
maximumBytes int The maximum bytes to decode.
return byte[]
        private static byte[] DecodeBase64(string encodedstring, int maximumBytes)
        {
            int position = 0,
                sourceLength = encodedstring.Length,
                outputLength = 0;

            if (maximumBytes <= 0)
                throw new ArgumentException("Invalid maximum bytes value", "maximumBytes");

            // TODO: update to use a List<byte> - it's only ever 16 bytes, so it's not a big deal
            StringBuilder rs = new StringBuilder();
            while (position < sourceLength - 1 && outputLength < maximumBytes)
            {
                int c1 = Char64(encodedstring[position++]);
                int c2 = Char64(encodedstring[position++]);
                if (c1 == -1 || c2 == -1)
                    break;

                rs.Append((char)((c1 << 2) | ((c2 & 0x30) >> 4)));
                if (++outputLength >= maximumBytes || position >= sourceLength)
                    break;

                int c3 = Char64(encodedstring[position++]);
                if (c3 == -1)
                    break;

                rs.Append((char)(((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2)));
                if (++outputLength >= maximumBytes || position >= sourceLength)
                    break;

                int c4 = Char64(encodedstring[position++]);
                rs.Append((char)(((c3 & 0x03) << 6) | c4));

                ++outputLength;
            }

            byte[] ret = new byte[outputLength];
            for (position = 0; position < outputLength; position++)
                ret[position] = (byte)rs[position];
            return ret;
        }