pc1*_*ter 5 .net security hash cryptography
我试图在JavaScript和.Net中生成等效的MD5哈希值.还没有做过,我决定使用第三方计算 - 这个网站上的"密码"这个词.我稍后会添加盐,但目前,我无法获得.net版本以匹配网站的哈希:
5f4dcc3b5aa765d61d8327deb882cf99
Run Code Online (Sandbox Code Playgroud)
我猜它是一个编码问题,但我已经尝试了8种不同的方法来计算.Net中的MD5哈希,并且它们都没有我在JavaScript(或从网站)中获得的.这个MSDN示例是我尝试过的方法之一,这导致我通常收到的这个哈希:
7c6a180b36896a0a8c02787eeafb0e4c
Run Code Online (Sandbox Code Playgroud)
编辑:可悲的是,我不小心为两个不同的实现提供了不同的源字符串.EBSAK.: - /仍然有兴趣听听你对后续行动的回答.
额外问题:什么编码/格式最适合在数据库中存储散列值?
从您引用的MSDN站点运行代码:
// Hash an input string and return the hash as
// a 32 character hexadecimal string.
static string getMd5Hash(string input)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
static void Main(string[] args)
{
System.Console.WriteLine(getMd5Hash("password"));
}
Run Code Online (Sandbox Code Playgroud)
收益:
5f4dcc3b5aa765d61d8327deb882cf99
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4173 次 |
| 最近记录: |