.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Encryption & Decryption >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Password Encyrption and Decryption

Posted By:Shashi Ray       Posted Date: August 19, 2009    Points: 10    Category: Encryption & Decryption    URL: http://www.dotnetspark.com  

Below Method is used to encrypt and decrypt  password string using C#. There are two method one is to encrypt and other for decrypt the string.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.VisualBasic;

public partial class PasswordEncyrption : System.Web.UI.Page
    protected void Button1_Click(object sender, EventArgs e)
        string sData = TextBox1.Text;
        Label3.Text  = PasswordEncryption(ref sData);
        Label3.Visible = true;
        Label2.Visible = true;
    protected void Button2_Click(object sender, EventArgs e)
        string sData = Label3.Text;
        TextBox1.Text = PasswordDecription(ref sData);
    public string PasswordDecryption(ref string Data)
        string Data1 = "";
        string sData = "";

        while (Data.Length > 0)
            Data1 = System.Convert.ToChar(System.Convert.ToUInt32(Data.Substring(0, 2), 16)).ToString();
            sData = sData + Data1;
            Data = Data.Substring(2, Data.Length - 2);
        return sData;
    public string PasswordEncryption(ref string Data)
        string sValue;
        string sHex = "";
        while (Data.Length > 0)

            sValue = Conversion.Hex(Strings.Asc(Data.Substring(0, 1).ToString()));
            Data = Data.Substring(1, Data.Length - 1);
            sHex = sHex + sValue;
        return sHex;


Shashi Ray


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend