Esempio n. 1
0
        private string CalcSignature(BasePacket parameter)
        {
            SortedDictionary <string, string> dicSorted = new SortedDictionary <string, string>();

            foreach (string item in dicParameter.Keys)
            {
                if (!string.IsNullOrEmpty(dicParameter[item]) && !item.EndsWith("_secret") && !item.EndsWith("_signature")
                    /*&& !item.EndsWith("_verifier") && !item.EndsWith("_callback")*/)
                {
                    dicSorted[item] = dicParameter[item];
                }
            }
            foreach (string item in parameter.dicParams.Keys)
            {
                if (!string.IsNullOrEmpty(parameter.dicParams[item]) && !item.EndsWith("_secret") && !item.EndsWith("_signature"))
                {
                    dicSorted[item] = parameter.dicParams[item];
                }
            }

            StringBuilder sb = new StringBuilder();

            foreach (string item in dicSorted.Keys)
            {
                sb.Append(item);
                sb.Append("=");
                CalcParamUri(sb, dicSorted[item]);
                sb.Append("&");
            }
            sb.Remove(sb.Length - 1, 1);            //마지막 & 지우기

            string baseStr = CalcBaseString(parameter.method, parameter.url, sb.ToString());
            string signKey = GetSignKey();            //Generate.ConsumerSecret + "&" + Generate.TokenSecret;//이게 문제
            string ret     = string.Empty;

            using (HMACSHA1 sha = new HMACSHA1(Encoding.ASCII.GetBytes(signKey)))
            {
                byte[] byteArray = Encoding.ASCII.GetBytes(baseStr);
                //MemoryStream stream = new MemoryStream(byteArray);//버그?
                byte[] hashvalue = sha.ComputeHash(byteArray);
                ret = Convert.ToBase64String(hashvalue);
                sha.Dispose();
            }
            return(ret);
        }
Esempio n. 2
0
        public string GetHeader(BasePacket parameter)
        {
            lock (lockObject)
            {
                Refresh();

                this.OAuthSignature = CalcSignature(parameter);

                StringBuilder sb = new StringBuilder();
                sb.Append("OAuth ");
                foreach (string item in dicParameter.Keys)
                {
                    if (!string.IsNullOrEmpty(dicParameter[item]) && !item.EndsWith("_secret")
                        /*&& !item.EndsWith("_verifier") && !item.EndsWith("_callback")*/)
                    {
                        sb.Append(item);
                        sb.Append("=\"");
                        CalcParamUri(sb, dicParameter[item]);
                        //sb.Append(Uri.EscapeDataString(dicParameter[item]));
                        sb.Append("\", ");
                    }
                }
                foreach (string item in parameter.dicParams.Keys)
                {
                    if (!string.IsNullOrEmpty(parameter.dicParams[item]))
                    {
                        sb.Append(item);
                        sb.Append("=\"");
                        CalcParamUri(sb, parameter.dicParams[item]);
                        //sb.Append(Uri.EscapeDataString(parameter.dicParams[item]));
                        sb.Append("\", ");
                    }
                }
                sb.Remove(sb.Length - 2, 2);

                return(sb.ToString());
            }
        }