title: OAuth - lexicographical byte value ordering in c#
body: <p>I have written an Service Provider implementation for OAuth and one of the Devs found a bug in the way the implementation was ordering query parameters.  I totally missed the <a href="http://oauth.net/core/1.0/#anchor14" rel="nofollow noreferrer">lexicographical ordering</a> requirement in the OAuth spec and was just doing a basic string sort on the name value parameters</p>
  
  <p>Given the following URI request from the consumer:</p>
  
  <pre><code>http://api.com/v1/People/Search?searchfor=fl&amp;communication=test@test.com&amp;Include=addresses
  </code></pre>
  
  <p>The resulting signature base should order the parameters as:</p>
  
  <pre><code>Include=addresses, communication=test@test.com, searchfor=fl
  </code></pre>
  
  <p>Given the following URI request from the consumer:</p>
  
  <pre><code>http://api.com/v1/People/Search?searchfor=fl&amp;communication=test@test.com&amp;include=addresses
  </code></pre>
  
  <p>The resulting signature base should order the parameters as:</p>
  
  <pre><code>communication=test@test.com, include=addresses, searchfor=fl
  </code></pre>
  
  <p>Note the case difference in the querystring parameter "include".  From what I understand, lexicographical byte value ordering will order parameters using the ascii value and then order asc.</p>
  
  <p>Since I = 73 and i = 105, the capital I should be ordered before the lowercase i.</p>
  
  <p>I have the following so far:</p>
  
  <pre><code>IEnumerable&lt;QueryParameter&gt; queryParameters = parameters
  .OrderBy(parm =&gt; parm.Key)
  .ThenBy(parm =&gt; parm.Value)
  .Select(
  parm =&gt; new QueryParameter(parm.Key, UrlEncode(parm.Value)));
  </code></pre>
  
  <p>But that will not cover the ascii character by character sort (IncLude=test&amp;Include=test will not sort properly).</p>
  
  <p>Any thoughts on how to make an efficient algorithm that will answer this problem? Or how to make the sort case sensitive via ICompare?  </p>