Exemplo n.º 1
0
        public static byte[] DecodeWithGzip(string source, string key, int expiry)
        {
            bool flag = source == null || key == null;

            byte[] result;
            if (flag)
            {
                result = null;
            }
            else
            {
                int num = 0;
                key = AuthCode.MD5(key);
                string str  = AuthCode.MD5(AuthCode.CutString(key, 16, 16));
                string text = AuthCode.MD5(AuthCode.CutString(key, 0, 16));
                string str2 = (num > 0) ? AuthCode.CutString(source, 0, num) : "";
                string pass = str + AuthCode.MD5(str + str2);
                byte[] input;
                try
                {
                    input = Convert.FromBase64String(AuthCode.CutString(source, num));
                }
                catch
                {
                    try
                    {
                        input = Convert.FromBase64String(AuthCode.CutString(source + "=", num));
                    }
                    catch
                    {
                        try
                        {
                            input = Convert.FromBase64String(AuthCode.CutString(source + "==", num));
                        }
                        catch
                        {
                            result = null;
                            return(result);
                        }
                    }
                }
                byte[] array   = AuthCode.RC4(input, pass);
                string @string = AuthCode.encoding.GetString(array);
                long   num2    = long.Parse(AuthCode.CutString(@string, 0, 10));
                byte[] array2  = new byte[array.Length - 26];
                Array.Copy(array, 26, array2, 0, array.Length - 26);
                byte[] array3 = new byte[array.Length - 26 + text.Length];
                Array.Copy(array2, 0, array3, 0, array2.Length);
                Array.Copy(AuthCode.encoding.GetBytes(text), 0, array3, array2.Length, text.Length);
                bool flag2 = (num2 == 0L || num2 - (long)AuthCode.GetCurrentTimeStamp() > 0L) && AuthCode.CutString(@string, 10, 16) == AuthCode.CutString(AuthCode.MD5(array3), 0, 16);
                if (flag2)
                {
                    result = array2;
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        private static string Authcode(string source, string key, AuthCode.AuthcodeMode operation, int expiry)
        {
            bool   flag = source == null || key == null;
            string result;

            if (flag)
            {
                result = "";
            }
            else
            {
                int num = 0;
                key = AuthCode.MD5(key);
                string str   = AuthCode.MD5(AuthCode.CutString(key, 16, 16));
                string str2  = AuthCode.MD5(AuthCode.CutString(key, 0, 16));
                string text  = (num > 0) ? ((operation == AuthCode.AuthcodeMode.Decode) ? AuthCode.CutString(source, 0, num) : AuthCode.RandomString(num)) : "";
                string pass  = str + AuthCode.MD5(str + text);
                bool   flag2 = operation == AuthCode.AuthcodeMode.Decode;
                if (flag2)
                {
                    byte[] input;
                    try
                    {
                        input = Convert.FromBase64String(AuthCode.CutString(source, num));
                    }
                    catch
                    {
                        try
                        {
                            input = Convert.FromBase64String(AuthCode.CutString(source + "=", num));
                        }
                        catch
                        {
                            try
                            {
                                input = Convert.FromBase64String(AuthCode.CutString(source + "==", num));
                            }
                            catch
                            {
                                result = "";
                                return(result);
                            }
                        }
                    }
                    string @string = AuthCode.encoding.GetString(AuthCode.RC4(input, pass));
                    long   num2    = long.Parse(AuthCode.CutString(@string, 0, 10));
                    bool   flag3   = (num2 == 0L || num2 - (long)AuthCode.GetCurrentTimeStamp() > 0L) && AuthCode.CutString(@string, 10, 16) == AuthCode.CutString(AuthCode.MD5(AuthCode.CutString(@string, 26) + str2), 0, 16);
                    if (flag3)
                    {
                        result = AuthCode.CutString(@string, 26);
                    }
                    else
                    {
                        result = "";
                    }
                }
                else
                {
                    source = ((expiry == 0) ? "0000000000" : (expiry + AuthCode.GetCurrentTimeStamp()).ToString()) + AuthCode.CutString(AuthCode.MD5(source + str2), 0, 16) + source;
                    byte[] inArray = AuthCode.RC4(AuthCode.encoding.GetBytes(source), pass);
                    result = text + Convert.ToBase64String(inArray);
                }
            }
            return(result);
        }