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

EncodeBase64() private static method

Encode a byte array using bcrypt's slightly-modified base64 encoding scheme. 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 EncodeBase64 ( byte byteArray, int length ) : string
byteArray byte The byte array to encode.
length int The number of bytes to encode.
return string
        private static string EncodeBase64(byte[] byteArray, int length)
        {
            if (length <= 0 || length > byteArray.Length)
                throw new ArgumentException("Invalid length", "length");

            int off = 0;
            StringBuilder rs = new StringBuilder();
            while (off < length)
            {
                int c1 = byteArray[off++] & 0xff;
                rs.Append(_Base64Code[(c1 >> 2) & 0x3f]);
                c1 = (c1 & 0x03) << 4;
                if (off >= length)
                {
                    rs.Append(_Base64Code[c1 & 0x3f]);
                    break;
                }
                int c2 = byteArray[off++] & 0xff;
                c1 |= (c2 >> 4) & 0x0f;
                rs.Append(_Base64Code[c1 & 0x3f]);
                c1 = (c2 & 0x0f) << 2;
                if (off >= length)
                {
                    rs.Append(_Base64Code[c1 & 0x3f]);
                    break;
                }
                c2 = byteArray[off++] & 0xff;
                c1 |= (c2 >> 6) & 0x03;
                rs.Append(_Base64Code[c1 & 0x3f]);
                rs.Append(_Base64Code[c2 & 0x3f]);
            }
            return rs.ToString();
        }