CRC32, , . .
In terms of hash primitive truncation, the only widely used application is the SSL / TLS (PRF) pseudo-random function , which is used to generate keys. It uses HMAC, seeds, and tags to generate as many bytes as you need, hashing several times and then trimming to the required number of bytes.
As for your specific question, you can read the hash output in Int32, and then combine them together if you are paranoid:
static void Main()
{
int xorCrc = GetHashedCrc(new SHA1Cng(), new byte[] {0xDE, 0xAD, 0xBE, 0xEF});
}
private static int GetHashedCrc(HashAlgorithm algorithm, byte[] bytesToHash)
{
byte[] hash = algorithm.ComputeHash(bytesToHash);
int totalInt32s = hash.Length/sizeof(int);
int result = 0;
for(int i = 0; i < totalInt32s; i++)
{
int currentInt = BitConverter.ToInt32(hash, sizeof(int)*i);
result = result ^ currentInt;
}
return result;
}
source
share