• How to Encrypt and Decrypt URL or Data using C# in ASP.NET MVC?

    by  • November 3, 2015 • Microsoft .NET C# (C-Sharp), Microsoft .NET Framework, Microsoft ASP.NET, Microsoft ASP.NET MVC • 0 Comments

    In any web application there are always security related problem occurs when user change something in URL’s value. When passing any sensitive data from navigation then it may problem occurs when use can change it and hake any of the data. So better option is store this value in session but every time this is not possible or good solution to store in session.

    In this article I am going to explain about URL encryption and decryption with any of the data. When you want to encrypt and decrypt URL or data in ASP.NET MVC using C# code then this would be helpful example.

    EncryptDecrypt.cs:

    We have created below methods for URL encryption and decryption in EmcryptDecrypt.cs class. Below are the code for encrypt string by Cryptography with MD5 algorithm.

    Model.cs:

    The Model comes to a simple class containing raw data. The source code of the model class is shown below:

    Controller.cs:

    Since there is no server-side processing, the controller class is also fairly simple and it calls URLDecrypt and URLEncrypt method for encrypting and decrypting data,  then shows to view. The controller class used in the example is shown below:

    View.cshtml:

    The View used in the example is shown below:

     




    Namecheap.com
    Avatar of Abdul Rehman

    About

    Abdul Rehman writes on .NET technologies at GetCodeSnippet.com. 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.

    http://getcodesnippet.com

    Leave a Reply