How to have the Uppercase Encoding for the string?http://forums.asp.net/t/1797378.aspx/1?How+to+have+the+Uppercase+Encoding+for+the+string+Thu, 03 May 2012 03:42:14 -040017973784953248http://forums.asp.net/p/1797378/4953248.aspx/1?How+to+have+the+Uppercase+Encoding+for+the+string+How to have the Uppercase Encoding for the string? <p>I need to Percent Encoding for my Url and Pararmeters. I am using UrlEncode, it works fine but it returns lower case but not the upper case. How can I have Uppercase for the encoded characters?<span style="color:blue"></span></p> <p><span style="color:blue">var</span>&nbsp;pEncodeUrl&nbsp;=&nbsp;<span style="color:#2b91af">HttpUtility</span>.UrlEncode(url);</p> <p>it gives like '<em><strong>https%3a%2f%2fapi.test.com</strong></em>' But i Need like '<em><strong>https%3A%2F%2Fapi.test.com</strong></em>'</p> <p>If I would <span style="color:blue">var</span>&nbsp;pEncodeUrl&nbsp;=&nbsp;<span style="color:#2b91af">HttpUtility</span>.UrlEncode(url).ToUpper(), It gives thw whole URL as Upper case which I dont need.</p> <p>How can I get it fixed?</p> <p>Thanks,</p> <p></p> 2012-04-26T15:29:21-04:004953323http://forums.asp.net/p/1797378/4953323.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>Why do you need it upper case?</p> 2012-04-26T16:11:42-04:004953330http://forums.asp.net/p/1797378/4953330.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>The percent-encoded representations <b><i>must</i></b> be capitalized in the base string which is passed into the HMAC-SHA1 function. In other words, : must be encoded as &quot;%3A&quot; instead of &quot;%3a&quot;.</p> 2012-04-26T16:13:16-04:004953335http://forums.asp.net/p/1797378/4953335.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>You might have to resort to calling UrlEncode() and then ToUpper() on just the part you want/need uppercase, and just UrlEncode() on the rest and then concatenate the two together.</p> <p></p> 2012-04-26T16:16:58-04:004953348http://forums.asp.net/p/1797378/4953348.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>I don't understand what you mean. I am using it right now and do not have this issue. I don't know what you mean by MUST. It's just an encryption technique. Doesn't matter what you pass it. As long as the client and server do the same thing, it works.</p> <pre class="prettyprint">string userkey = _users[token.PublicKey]; byte[] secretBytes = ASCIIEncoding.ASCII.GetBytes(userkey); HMACSHA256 hmac = new HMACSHA256(secretBytes); byte[] dataBytes = ASCIIEncoding.ASCII.GetBytes(uri &#43; token.Timestamp); byte[] computedHash = hmac.ComputeHash(dataBytes); string computedHashString = Convert.ToBase64String(computedHash); return computedHashString.Equals(token.Signature);</pre> <pre class="prettyprint"><br /><br /></pre> <pre class="prettyprint"><br /><br /></pre> <p></p> 2012-04-26T16:27:25-04:004953414http://forums.asp.net/p/1797378/4953414.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>digitalpacman</h4> <p></p> <p>... I don't know what you mean by MUST. It's just an encryption technique. Doesn't matter what you pass it. As long as the client and server do the same thing, it works.</p> <p></p> </blockquote> <p></p> <p>Right, I suspect this is the issue. Perhaps he's sending this off to some other app and it's expecting the casing the way he described.</p> <p></p> 2012-04-26T17:05:06-04:004953465http://forums.asp.net/p/1797378/4953465.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>Loop over it with a regex and do replacements. Only thing I got. I don't know of any &quot;upper case only url encoding&quot; built into .net. You, and the person you're dealing with, should probably be SHA'ing the pre-encoded value to avoid these problems.</p> <p>%[a-zA-Z0-9]{2}</p> <p>Match that and loop over doing replacements to the upper case version.</p> 2012-04-26T17:48:28-04:004953469http://forums.asp.net/p/1797378/4953469.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p><br> split(&quot;%&quot;)</p> <p>for (i = 1; i &lt; length; i &#43;= 2)<br> &nbsp; &nbsp;items[i] = items[i].ToUpper()<br> &nbsp;<br> .join(&quot;%&quot;)</p> 2012-04-26T17:50:34-04:004953492http://forums.asp.net/p/1797378/4953492.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>Thanks, I got it through like below</p> <pre style="font-family:Consolas; font-size:13px; color:black; background:none repeat scroll 0% 0% white"><span style="color:blue">private</span>&nbsp;<span style="color:blue">static</span>&nbsp;<span style="color:blue">string</span>&nbsp;UrlEncodeUpperCase(<span style="color:blue">string</span>&nbsp;stringToEncode) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">var</span>&nbsp;reg&nbsp;=&nbsp;<span style="color:blue">new</span>&nbsp;<span style="color:#2b91af">Regex</span>(<span style="color:#a31515">@&quot;%[a-f0-9]{2}&quot;</span>); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stringToEncode&nbsp;=&nbsp;<span style="color:#2b91af">HttpUtility</span>.UrlEncode(stringToEncode); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue">return</span>&nbsp;reg.Replace(stringToEncode,&nbsp;m&nbsp;=&gt;&nbsp;m.Value.ToUpperInvariant()); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</pre> 2012-04-26T18:07:42-04:004953600http://forums.asp.net/p/1797378/4953600.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>The split ,method is probably like 10x faster. but coo.</p> 2012-04-26T19:22:35-04:004955521http://forums.asp.net/p/1797378/4955521.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>The simplest way to do this is to use the best method available in .NET for encoding URIs: Uri.EscapeDataString.</p> <pre class="prettyprint">&gt; System.Uri.EscapeDataString(&quot;https://api.test.com&quot;);; val it : string = &quot;https%3A%2F%2Fapi.test.com&quot;</pre> <p>See <a href="http://blogs.msdn.com/b/yangxind/archive/2006/11/09/don-t-use-net-system-uri-unescapedatastring-in-url-decoding.aspx"> also</a>.</p> 2012-04-27T20:46:26-04:004962855http://forums.asp.net/p/1797378/4962855.aspx/1?Re+How+to+have+the+Uppercase+Encoding+for+the+string+Re: How to have the Uppercase Encoding for the string? <p>Did my answer help? I'm curious if it doesn't work, as it appeared to do exactly what you needed.</p> 2012-05-03T03:42:14-04:00