码迷,mamicode.com
首页 > 编程语言 > 详细

C# QQ的一段skey转bkn算法

时间:2016-11-24 08:41:15      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:ogr   conf   config   pre   void   return   let   null   key   

private void webBrowserLogin_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //加载完成
            if (webBrowserLogin.Url.Host.ToLower() == "qun.qq.com")
            {
                if (webBrowserLogin.Document.Cookie != null)
                {
                    //Config.myCookieContainer = null;
                    Config.cookies = webBrowserLogin.Document.Cookie;
                    string[] cookies = webBrowserLogin.Document.Cookie.Split(;);
                    foreach (string str in cookies)
                    {
                        string[] keyvalue = str.Trim().Split(=);
                        Cookie ck = new Cookie(keyvalue[0], keyvalue[1]);
                        ck.Domain = ".qq.com";
                        Config.myCookieContainer.Add(ck);
                        if (keyvalue[0].ToLower().Equals("skey"))
                        {
                            string value = keyvalue[1];
                            Config.bkn = SkeyToBkn(value);
                        }
                        if (keyvalue[0].ToLower().Equals("uin"))
                        {
                            Config.uin = GetUin(keyvalue[1]);
                        }
                    }
                    this.DialogResult = DialogResult.OK;                                      
                }
            }
        }

        /// <summary>
        /// skey转bkn
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private string SkeyToBkn(string str)
        {
            int hash = 5381;
            for (int i = 0; i < str.Length; ++i)
            {
                hash += (hash << 5) + (int)str[i];
            }
            return (hash & 2147483647).ToString();
        }

        /// <summary>
        /// 通过uin获取QQ号
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private string GetUin(string str)
        {
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] != o && str[i] != 0)
                {
                    return str.Substring(i, str.Length - i);
                }
            }
            return null;
        }

 

C# QQ的一段skey转bkn算法

标签:ogr   conf   config   pre   void   return   let   null   key   

原文地址:http://www.cnblogs.com/testsec/p/6095959.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!