• How to Encrypt and Decrypt Query String values in C#

    by  • June 10, 2013 • Microsoft .NET C# (C-Sharp), Microsoft ASP.NET • 1 Comment

    We pass values form one page to another using different techniques and query string is one of them. Query String is a good way to pass values between pages but it is not reliable. People can play with these values because these are in plain text. We can use other techniques available to pass values between pages but sometimes we really need query string. So when we need query string to pass values between pages and we also want to secure our values then we can encrypt our string and pass this encrypted string as query string parameters and values. We can decrypt this string in the next page to get query string parameters and values.

    Let’s see how we can encrypt and decrypt Query String values.

    Encrypt Query String Function

    Now see code below, I am passing query string values to Encrypt() function and redirecting to another page.

    Decrypt Query String Function

    I am getting the encrypted string from this URL and calling the Decrypt() function here.




    Namecheap.com
    Avatar of GetCodeSnippet.com

    About

    GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    One Response to How to Encrypt and Decrypt Query String values in C#

    1. May 16, 2014 at 7:09 am

      I ended up using your example in my own project.
      Just extended the Encrypt and Decrypt methods with a key parameter, since this was suitable in my case. Great article 🙂

    Leave a Reply