By Team Escalera
on 31 Oct 2017 03:19 PM
  • asp.net training
0 comments

Text to md5 in C Sharp Password Encryption

To Convert a value from TextBox in Asp.net using C# into md5 hash

use following assembly reference in your page
using System.Security.Cryptography; \\FOR MD5

using System.Text;\\For ASCII encoding

And code :

public string GetMD5(string text)

        {

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(text));

            byte[] result = md5.Hash;

            StringBuilder str = new StringBuilder();

            for (int i = 1; i < result.Length; i++)

            {

                str.Append(result[i].ToString(“x2”));

            }

            return str.ToString();

        }

Now our Method is Created to Convert Strings into MD5

Simply write following Code to Change password.text to a Textbox.Text value.

TextBox.Text = GetMD5(Pass.Text);

Comments (0)

Leave A Comment