/// <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());
        }
        /// <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();
 }