HttpUtility.UrlEncoding uppercase response

Posted on 2011-10-07
Last Modified: 2012-05-12
Hi experts.

I'm creating a oAuth protocol library on ASP.NET MVC and I've found something that surprised me.

In the oAuth authentication dance, you have to send often url encoded strings to a remote server in order to get authorization from users of that server into your app. For obvious security reasons, those strings had to be signed using a hashing algorithm (usually HMAC-SHA1).

Into these strings comes the url-encoded http petition to the target url on the remote server, and here comes the problem. I've checked that HttpUtility.UrlEncode returns the url encoded entities on lowercase. I mean, if your url includes "=", it will be transformed into "%3d".

Usually, this shouldn't be a problem, but, when I sign my encoded url with HMAC-SHA1 the result obviously varies from %3d to %3D, and I've found that several servers (linkedIn for example) expect into the request mades to it's servers that the url encoding had been made with uppercase.

As a result of this, the signed hashed string that I send doesn't match with the one that the server expects (due to characters being on lowercase on source and uppercase on destination) and the authorization dance stops with an error.

I've fixed this with some very unelegant replaces into the string before making the signing, as I can't simply turn all my string into uppercase, but I'm wondering if ASP.NET would provide me a smoother way to turn that url encoded entities to uppercase.

Any suggestions?
Question by:Bardobrave
    LVL 3

    Accepted Solution

    UrlEncode is the old way of doing it (i think :)  ) I think what you are looking for is System.Uri.EscapeDataString(string);

    Hope it works for you
    LVL 19

    Author Closing Comment

    Exactly what I was looking for. Thankyou.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now