MD5 hash with salt for keeping password in DB in C#

前端 未结 4 1714
一向
一向 2020-11-27 03:59

Could you please advise me some easy algorithm for hashing user password by MD5, but with salt for increasing reliability.

Now I have this one:

4条回答
  •  眼角桃花
    2020-11-27 04:30

    In addition to the HMACSHA1 class mentioned above, if you just need a quick salted hash, then you're already 95% of the way there:

    private static string GenerateHash(string value, string salt)
    {
        byte[] data = System.Text.Encoding.ASCII.GetBytes(salt + value);
        data = System.Security.Cryptography.MD5.Create().ComputeHash(data);
        return Convert.ToBase64String(data);
    }
    

    The real trick is storing the salt in a secure location, such as your machine.config.

提交回复
热议问题