/// <summary>
        /// Generates and signs the signature base string
        /// </summary>
        /// <param name="httpsURL"></param>
        /// <param name="requestMethod"></param>
        /// <param name="oparams"></param>
        /// <returns></returns>
        private string generateAndSignSignature(String httpsURL, String requestMethod, OAuthParameters oparams)
        {
            OAuthParameters sbsParams = new OAuthParameters();

            sbsParams.putAll(oparams.getBaseParameters());

            string realm = null;

            if (sbsParams.get(REALM) != EMPTY_STRING)
            {
                realm = sbsParams.get(REALM);
                sbsParams.remove(REALM, null);
            }
            String baseString;

            baseString           = generateSignatureBaseString(httpsURL, requestMethod, sbsParams);
            _signatureBaseString = baseString;

            String signature;

            signature = sign(baseString, privateKey);
            oparams.addParameter(OAUTH_SIGNATURE, signature);
            if (realm != null)
            {
                sbsParams.put(REALM, realm);
            }
            return(signature);
        }
 /// <summary>
 /// Method to build a comma delimited list of key/value string for the signature base string and authorization header
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="oparams"></param>
 /// <returns></returns>
 private StringBuilder parseParameters(StringBuilder buffer, OAuthParameters oparams)
 {
     foreach (KeyValuePair <string, SortedSet <string> > key in oparams.getBaseParameters())
     {
         SortedSet <string> value = key.Value;
         parseSortedSetValues(buffer, key.Key, value);
         buffer.Append(COMMA);
     }
     buffer.Remove(buffer.Length - 1, 1);
     return(buffer);
 }
        /// <summary>
        /// Normalize the OAuth parameters as they are added to the signature base string
        /// </summary>
        /// <param name="httpUrl"></param>
        /// <param name="requestParameters"></param>
        /// <returns></returns>
        private static String normalizeParameters(String httpUrl, OAuthParameters requestParameters)
        {
            // add the querystring to the base string (if one exists)
            if (httpUrl.IndexOf(QUESTION_MARK) > 0)
            {
                NameValueCollection queryParameters = HttpUtility.ParseQueryString(httpUrl.Substring(httpUrl.IndexOf(QUESTION_MARK) + 1));
                foreach (string key in queryParameters)
                {
                    requestParameters.put(key, UrlEncodeRfc3986(queryParameters[key]));
                }
            }
            // piece together the base string, encoding each key and value
            StringBuilder paramString = new StringBuilder();

            foreach (KeyValuePair <string, SortedSet <string> > kvp in requestParameters.getBaseParameters())
            {
                if (kvp.Value.Count == 0)
                {
                    continue; // Skip if key doesn't have any values
                }
                if (paramString.Length > 0)
                {
                    paramString.Append(AMP);
                }
                int tempCounter = 0;
                foreach (string value in kvp.Value.Keys)
                {
                    paramString.Append(UrlEncodeRfc3986(kvp.Key)).Append(EQUALS).Append((value));
                    if (tempCounter != kvp.Value.Count - 1)
                    {
                        paramString.Append(AMP);
                    }
                    tempCounter++;
                }
            }
            return(paramString.ToString());
        }
 /// <summary>
 /// Method to build a comma delimited list of key/value string for the signature base string and authorization header
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="oparams"></param>
 /// <returns></returns>
 private StringBuilder parseParameters(StringBuilder buffer, OAuthParameters oparams)
 {
     foreach (KeyValuePair<string, SortedSet<string>> key in oparams.getBaseParameters())
     {
         SortedSet<string> value = key.Value;
         parseSortedSetValues(buffer, key.Key, value);
         buffer.Append(COMMA);
     }
     buffer.Remove(buffer.Length - 1, 1);
     return buffer;
 }
        /// <summary>
        /// Generates and signs the signature base string
        /// </summary>
        /// <param name="httpsURL"></param>
        /// <param name="requestMethod"></param>
        /// <param name="oparams"></param>
        /// <returns></returns>
        private string generateAndSignSignature(String httpsURL, String requestMethod, OAuthParameters oparams)
        {
            OAuthParameters sbsParams = new OAuthParameters();
            sbsParams.putAll(oparams.getBaseParameters());

            string realm = null;
            if (sbsParams.get(REALM) != EMPTY_STRING)
            {
                realm = sbsParams.get(REALM);
                sbsParams.remove(REALM, null);
            }
            String baseString;
            baseString = generateSignatureBaseString(httpsURL, requestMethod, sbsParams);
            _signatureBaseString = baseString;

            String signature;
            signature = sign(baseString, privateKey);
            oparams.addParameter(OAUTH_SIGNATURE, signature);
            if (realm != null)
            {
                sbsParams.put(REALM, realm);
            }
            return signature;
        }
 /// <summary>
 /// Normalize the OAuth parameters as they are added to the signature base string
 /// </summary>
 /// <param name="httpUrl"></param>
 /// <param name="requestParameters"></param>
 /// <returns></returns>
 private static String normalizeParameters(String httpUrl, OAuthParameters requestParameters)
 {
     // add the querystring to the base string (if one exists)
     if (httpUrl.IndexOf(QUESTION_MARK) > 0)
     {
         NameValueCollection queryParameters = HttpUtility.ParseQueryString(httpUrl.Substring(httpUrl.IndexOf(QUESTION_MARK) + 1));
         foreach (string key in queryParameters)
         {
             requestParameters.put(key, UrlEncodeRfc3986(queryParameters[key]));
         }
     }
     // piece together the base string, encoding each key and value
     StringBuilder paramString = new StringBuilder();
     foreach (KeyValuePair<string, SortedSet<string>> kvp in requestParameters.getBaseParameters())
     {
         if (kvp.Value.Count == 0)
         {
             continue; // Skip if key doesn't have any values
         }
         if (paramString.Length > 0)
         {
             paramString.Append(AMP);
         }
         int tempCounter = 0;
         foreach (string value in kvp.Value.Keys)
         {
             paramString.Append(UrlEncodeRfc3986(kvp.Key)).Append(EQUALS).Append((value));
             if (tempCounter != kvp.Value.Count - 1)
             {
                 paramString.Append(AMP);
             }
             tempCounter++;
         }
     }
     return paramString.ToString();
 }