How to encrypt text in ASP.Net with C# - ASP TANMOY

Latest

Saturday, 28 December 2013

How to encrypt text in ASP.Net with C#



Description:
Today I am explaining about an application which can encrypt Text. When we insert data to database then we always need to encode data for security purpose. If any middlemen access this data they will not understand your content. So encrypt require whenever will you insert data to your database. This encryption is 64 bit encryption. This encryption will protect your content from theft.


What is encryption?
Encryption is the process of encrypt or convert content or message in different form so that third parties can’t understand original content or message. 

Step1:
i)             Open your visual studio.
ii)           Create an empty web form
iii)          Take to label, two textbox and a button from tool box. Design your page as follows:
 
 First textbox use for enter your content and second textbox use to show your converted or encrypted text. When you will click to the button then your converted text will show to the second textbox. 

 Step2:  

Copy the code to the code page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class loginpage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        byte[] enbyte = new byte[TextBox1.Text.Length];
        enbyte = System.Text.Encoding.UTF8.GetBytes(TextBox1.Text);
        string encodedData = Convert.ToBase64String(enbyte);
        TextBox2.Text = encodedData.ToString();
    }
}

Step3:

Run the page and Enjoy.

Output:
   


 





No comments:

Post a Comment