Click here to Skip to main content
12,405,230 members (72,604 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
I am first using md5 encrpt one string and saving binary in database ..
how to retrieve the binary   value using
Decrypt MD5 in ASP.Net?
Posted 12-Jan-12 18:14pm
goplappu1.2K
Updated 12-Jan-12 18:55pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Uma Shankar Patel 13-Jan-12 0:34am
   
5!
good article link...
Tech Code Freak 13-Jan-12 0:51am
   
5up! Great link.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

encoding
protected void Button2_Click(object sender, EventArgs e)
   {
       try
       {
           string str = "update AdminLogin set password=@password where userid=@userid";
           SqlCommand cmd = new SqlCommand(str, Db.GetConnection());
           cmd.Parameters.AddWithValue("@userid", TextBox2.Text);
 
           MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
 
           byte[] hashedBytes = null;
           UTF8Encoding encoder = new UTF8Encoding();
 
           hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBox3.Text));
 
           SqlParameter sqp = new SqlParameter("@password", System.Data.SqlDbType.Binary, 16);
           sqp.Value = hashedBytes;
           cmd.Parameters.Add(sqp);
 
           cmd.ExecuteNonQuery();
       }
       catch (Exception ex)
       {
           Response.Write(ex.ToString());
       }
 

   }

Decoding
protected void Button1_Click1(object sender, EventArgs e)
    {
        try
        {
            cnn.Open();
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            SqlDataReader dr;
            cmd.CommandText = "select * from AdminLogin where UserID=@userid and password=@pass";
            cmd.Parameters.AddWithValue("userid", TextBox1.Text);
            MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
            byte[] hashedBytes = null;
            UTF8Encoding encoder = new UTF8Encoding();
            hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBox2.Text));
            SqlParameter sqp = new SqlParameter("@pass", SqlDbType.Binary, 16);
            string strpa = hashedBytes.ToString();
            sqp.Value = hashedBytes;
            cmd.Parameters.Add(sqp);
 
            //string result = cmd.ExecuteScalar().ToString();
            //cmd.Parameters.AddWithValue("pass", TextBox2.Text);
             cmd.Connection = cnn;
            da.SelectCommand = cmd;
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Session["name"] = dr["name"].ToString();
             }
}
catch(Exception ex)
{
}
}
  Permalink  
v2
Comments
NandaKumer 13-Jan-12 1:25am
   
good one
Uma Shankar Patel 13-Jan-12 5:48am
   
thanks, you can rate it......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 13 Jan 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100