String.GetHashCode
Swedish Social Security Numbers (personnummer): Successfully inserted 8395 rows into a unique column in my test database before stumbling upon a unique constraint violation.
String.GetHashCode is not unique enough for this approach.
System.Security.Cryptography.MD5CryptoServiceProvider worked better, as did the SHA512Crypto - 2 million hash values with no collisions.
var generator = new System.Security.Cryptography.MD5CryptoServiceProvider();
...
var input = System.Text.Encoding.UTF8.GetBytes(reader.GetString(0));
var output = Convert.ToBase64String(generator.ComputeHash(input));
String.GetHashCode is not unique enough for this approach.
System.Security.Cryptography.MD5CryptoServiceProvider worked better, as did the SHA512Crypto - 2 million hash values with no collisions.
var generator = new System.Security.Cryptography.MD5CryptoServiceProvider();
...
var input = System.Text.Encoding.UTF8.GetBytes(reader.GetString(0));
var output = Convert.ToBase64String(generator.ComputeHash(input));
Comments