Subscribe to Subscribers

Online Members

Shine S
More...

Resources » Code Snippets » Encryption

Password Encryption & Decryption using C#


Posted Date:     Category: Encryption    
Author: Member Level: Gold    Points: 10



Password Encryption & Decryption using C#:



This resource demonstrates to encrypt and decrypt your password as you want.

1. Add reference to the Microsoft.VisualBasic class.
2. Place a Label Control to display the Encrypted Password.
3.Below is the code that is used to convert a string to hexadecimal format. We cannot directly convert all characters into hexadecimal format.So first we take the ASCII value of the character and then convert the ASCII value into hexadecimal format.

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;
}

}






Did you like this resource? Share it with your friends and show your love!


Responses to "Password Encryption & Decryption using C#"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Encryption and Decryption of a Querystring
    Previous Resource: Encryption and Decryption in C#
    Return to Resources
    Post New Resource
    Category: Encryption


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.