Asp.net

URL Encryption

Why:

It always good to send query string values in encrypted format. Encrypted URLs prevents sending illegal requests or invalid data to the application server. Users or attackers cannot see the request details of the URL as they are encrypted.

Example

Before encryption,

http://localhost:60608/EncryptURLDemo/Default2.aspx?text=amol

After encryption,

http://localhost:60608/EncryptURLDemo/Default2.aspx?q=dSoxSTYQLHY3arcO+hfCO7uMyRNnIpRCoUqk0oyR80c=

How:

Method 1: Manually encrypt / decrypt query string parameter

  1. Copy EncryptionHelper.dll into Bin directory of your web application.
  2. To encrypt query string values,
    string url=string.Format("~/Default2.aspx?text= {0}",EncryptionHelper.Encrypt("valuehere"));
  3. To decrypt query string values,
    if (Request.QueryString["text"] != null)
    Text = EncryptionHelper.Decrypt(Request.QueryString["text"]);

Method 2: Automatic encrypt / decrypt query string using HttpModule

  1. Copy EncryptionHelper.dll into Bin directory of your web application.
  2. Add the following lines to the web.config’s section:
    <httpModules>
     <add type = "QueryStringModule" name = "QueryStringModule" />
    </httpModules>

Leave a comment