FlickrNet.Twitter.OAuthCalculateSignature C# (CSharp) Méthode

OAuthCalculateSignature() public méthode

Calculates the signature for an OAuth call.
public OAuthCalculateSignature ( string method, string url, string>.Dictionary parameters, string tokenSecret ) : string
method string POST or GET method.
url string The URL the request will be sent to.
parameters string>.Dictionary Parameters to be added to the signature.
tokenSecret string The token secret (either request or access) for generating the SHA-1 key.
Résultat string
        public string OAuthCalculateSignature(string method, string url, Dictionary<string, string> parameters, string tokenSecret)
        {
            string baseString = "";
            string key = ApiSecret + "&" + tokenSecret;
            byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key);


            var sorted = parameters.OrderBy(p => p.Key);


            StringBuilder sb = new StringBuilder();
            foreach (KeyValuePair<string, string> pair in sorted)
            {
                if (pair.Key == "method")
                {

                }
                else
                {
                    sb.Append(pair.Key);
                    sb.Append("=");
                    sb.Append(UtilityMethods.EscapeOAuthString(pair.Value));
                    sb.Append("&");
                }
            }

            sb.Remove(sb.Length - 1, 1);

            baseString = method + "&" + UtilityMethods.EscapeOAuthString(url) + "&" + UtilityMethods.EscapeOAuthString(sb.ToString());



            //System.Security.Cryptography.HMACSHA1 sha1 = new System.Security.Cryptography.HMACSHA1(keyBytes);


            //byte[] hashBytes = sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(baseString));

            //string hash = Convert.ToBase64String(hashBytes);
            string hash = UtilityMethods.Sha1Encrypt(baseString, key);

            Debug.WriteLine("key  = " + key);
            Debug.WriteLine("base = " + baseString);
            Debug.WriteLine("sig  = " + hash);

            return hash;
        }