Rid*_*lah -1 c# encryption hash cryptography
我创建了哈希.比我在控制台上打印它.复制哈希值并将其放入代码进行比较.但它产生的不一样.
String input = "Hello";
String key = "Key";
Byte[] hashKey = Encoding.UTF8.GetBytes(key);
HMACSHA1 hmac = new HMACSHA1(hashKey);
Byte[] computedHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(input));
String computedHashString = Encoding.UTF8.GetString(computedHash);
Console.WriteLine("Hash value of your input: .{0}.", computedHashString);
if ("?:????W?u$YLR;???T?j" == computedHashString)
{
Console.WriteLine("They are same!");
}
else
{
Console.WriteLine("They are NOT same!");
}
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

先感谢您
哈希的结果不是UTF-8编码的文本,不应该这样对待.将其转换为十六进制或base64.例如:
string computedHashString = Convert.ToBase64String(computedHash);
Run Code Online (Sandbox Code Playgroud)
从根本上说,您需要仔细处理数据.将哈希的结果转换为文本就像尝试将mp3文件加载到图片查看器中,或尝试解压缩应用压缩算法的结果.
| 归档时间: |
|
| 查看次数: |
93 次 |
| 最近记录: |