HashAlgorithm.Create mthod not working in .Net Framework 4.0 RRS feed

  • Question

  • User1681850071 posted


    I am using below method to encode password and save it into database.

            static string EncodePassword(string pass, string salt)
                byte[] bIn = Encoding.Unicode.GetBytes(pass);
                byte[] bSalt = Convert.FromBase64String(salt);
                byte[] bAll = new byte[bSalt.Length + bIn.Length];
                byte[] bRet = null;
                Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
                Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
                HashAlgorithm s = HashAlgorithm.Create(Membership.HashAlgorithmType); // SHA1
                bRet = s.ComputeHash(bAll);
                return Convert.ToBase64String(bRet);

    Above method was working fine when I was running my project on Framework 3.5. If I change my project framework veirsion to 4.0 the above method returns me defferent string for same pass, and same salt each time. Becase of this problem even user enter same password on login page, he/she can't login.

    I try to search on google and msdn but I could not found any proper reason. Can any one help me to find out the correct reasion that why this method is working in 3.5 and not in 4.0.

    Please HELP.


    Sunday, August 7, 2011 1:47 AM


All replies