Click here to Skip to main content
11,708,312 members (72,768 online)
Rate this: bad
good
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.1K
Edited 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 at 13-Jan-12 0:34am
   
5!
good article link...
Tech Code Freak at 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 at 13-Jan-12 1:25am
   
good one
Uma Shankar Patel at 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
0 Maciej Los 245
1 Sergey Alexandrovich Kryukov 189
2 Mika Wendelius 180
3 Peter Leow 130
4 OriginalGriff 103
0 OriginalGriff 9,253
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,966
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 13 Jan 2012
Copyright © CodeProject, 1999-2015
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