0

I have 2 two page. MainPage.aspx and DealerPage.aspx

I send a Request QueryString from MainPage to DealerPage but I want QueryString to be encrypt when passing to DealerPage

In MainPage.aspx (Javascript)

              google.maps.event.addListener(marker2, "click", function (e) {

              infoWindow2.setContent(data2.description);
              infoWindow2.open(map2, marker2);
              window.location = "DealerPage.aspx?DI=" + data2.plate;
              icon: InitIcon


              });

E.g

             http:localhost/DealerPage.aspx?DI=485180610

In DealerPage.aspx.cs I get and use QueryString.

             private string tankerPlate = "";

             protected void Page_Load(object sender, EventArgs e)

            {

             this.truckPlate = this.Page.Request.QueryString["DI"];

             }

I dont want display like DI=485180610.

I want to be DI=encrypt and decrypt for using next page.

Mhmt
  • 759
  • 3
  • 22
  • 45
  • possible duplicate of [How to encrypt query string values passing from gridview in asp.net?](http://stackoverflow.com/questions/14013298/how-to-encrypt-query-string-values-passing-from-gridview-in-asp-net) – Subin Jacob Dec 09 '13 at 10:41

1 Answers1

1

Try this

public static class Crypt
{
    // Must be random
    private static readonly byte[] key = new byte[24] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4 };

    public static string Encrypt(string input)
    {
        byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input);
        TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
        tripleDES.GenerateKey();
        tripleDES.Key = key;
        tripleDES.Mode = CipherMode.ECB;
        tripleDES.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tripleDES.CreateEncryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
        tripleDES.Clear();
        return Convert.ToBase64String(resultArray, 0, resultArray.Length);
    }

    public static string Decrypt(string input)
    {
        byte[] inputArray = Convert.FromBase64String(input);
        TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
        tripleDES.Key = key;
        tripleDES.Mode = CipherMode.ECB;
        tripleDES.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tripleDES.CreateDecryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
        tripleDES.Clear();
        return UTF8Encoding.UTF8.GetString(resultArray);
    }
}

Or try this CodeProject Article.

Subin Jacob
  • 4,692
  • 10
  • 37
  • 69
  • How can I use that for when click google maps markers ? I used window.location = "DealerPage.aspx?DI=" + data.plate; on google map – Mhmt Dec 09 '13 at 10:51
  • Try this then http://madskristensen.net/post/HttpModule-for-query-string-encryption – Subin Jacob Dec 09 '13 at 10:53