Any built-in hash function should do; depending on how much you care about collisions, these are your options (from most conflicts to a minimum):
- MD5
- SHA1
- SHA256
- SHA384
- SHA512
They are as easy to use as:
var hash = SHA1.Create().ComputeHash(data);
Bonus signs: If you donโt care about security (which I donโt think you give hashes for images), you can look at the murmur hash, which is intended for hashing content and insecure hashing (and therefore much faster) . However, this is not the case, so you will need to find an implementation (and you probably should go for Murmur3).
Edit: If you are looking for a HASHCODE for a byte [] array, it is entirely up to you, it usually consists of a bit offset (by simple characters) and XORing, for example.
public class ByteArrayEqualityComparer : IEqualityComparer<byte[]> { public static readonly ByteArrayEqualityComparer Default = new ByteArrayEqualityComparer(); private ByteArrayEqualityComparer() { } public bool Equals(byte[] x, byte[] y) { if (x == null && y == null) return true; if (x == null || y == null) return false; if (x.Length != y.Length) return false; for (var i = 0; i < x.Length; i++) if (x[i] != y[i]) return false; return true; } public int GetHashCode(byte[] obj) { if (obj == null || obj.Length == 0) return 0; var hashCode = 0; for (var i = 0; i < obj.Length; i++)
EDIT: If you want to verify that the value has not changed, you must use CRC32 .
source share