Ejemplo n.º 1
0
        private string GenerateOAuthSignature(string url, string method, ArrayList allParameters, string tokenSecret)
        {
            // The parameters must be sorted by key name before generating the signature hash
            //allParameters = (ArrayList)allParameters.OrderBy(s => s);
            //allParameters.OrderBy(s=>s).
            object[] sortedParameters = (object[])allParameters.OrderBy(s => s, (a, b) => ((IComparable)a).CompareTo(b));

            // Get the parameters in the form of a query string
            string normalizedParameters = HTTPUtility.ParameterListToQueryString(sortedParameters);

            // Concatenate the HTTP method, URL, and parameter string
            string signatureBase = method + '&' + HTTPUtility.UrlEncode(url) + '&' + HTTPUtility.UrlEncode(normalizedParameters);

            // Get a byte array of the signatureBase
            byte[] data = Encoding.UTF8.GetBytes(signatureBase);

            // Get the key
            string key = consumerSecret + '&' + tokenSecret;
            byte[] keyBytes = Encoding.UTF8.GetBytes(key);

            // Compute the HMAC-SHA1 hash
            byte[] hashBytes = SHA.computeHMAC_SHA1(keyBytes, data);

            // The signature is a Base64 encoded version of the hash
            return HTTPUtility.ConvertToBase64String(hashBytes);
        }