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));

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints