I created hash. Than I printed it in console. Copied hash value and put it to code for comparsion. But it yield that they are not same.
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();
Thank you in Advance
The result of a hash isn't UTF-8-encoded text, and shouldn't be treated that way. Convert it to hex or base64. For example:
string computedHashString = Convert.ToBase64String(computedHash);
Fundamentally, you need to treat data carefully. Converting the result of a hash to text is like trying to load an mp3 file into a picture viewer, or trying to unzip the result of applying a compression algorithm.
See more on this question at Stackoverflow