Recently, I noticed that SHA algorithm computes hashes with random length.
HashAlgorithm provider;
provider = HashAlgorithm.Create("System.Security.Cryptography.SHA256");
while(!stackoverflow) {
Console.WriteLine(Encoding.UTF8.GetString(
provider.ComputeHash(Encoding.UTF8.GetBytes(
(new Random()).Next().ToString())))
.Count().ToString());
}
Outputs:
29
29
30
29
29
30
29
31
29
29
32
29
30
28
...
Is it possible to set the maximum hash length? (Could make the hash useless..) Or am I doing something wrong in computing the hashes? Encoding?
Edit:
The snippet above is just an example. What I need in the end is a method that takes a string, computes the hash of the string and returns it. HashAlgorithm.ComputeHash
takes bytes and returns bytes, so I used UTF8.GetBytes()
/UTF8.GetString()
for converting which seems to be a huge mistake.