我正在研究一些C#安全代码,并且当我看到它正在使用HMACSHA1类时即将替换它。该代码用于散列密码以存储在数据库中。引起我注意的事情是,它使用密码作为HMAC密钥,这正是计算哈希的密码。那么是使用密钥和哈希的东西的数据好吗?这会使安全性变得更强还是更弱?HMAC SHA1使用相同的密钥和消息值
伪代码:
string pwd = "[email protected]#123$";
using (HMACSHA1 hasher = new HMACSHA1())
{
hasher.Key = encoding.GetBytes(pwd); // using password for the key
return BytesToHex(hasher.ComputeHash(encoding.GetBytes(pwd))); // computing the hash for the password
}