I’m passing a name string and its SHA1 value into a database. The SHA value is used as an index for searches. After the implementation was done, we got the requirement to make searching the name case insensitive. We do need to take all languages into account (Chinese characters are a real use case).
I know about the Turkey Test. How can I transform my input string before hashing to be case insensitive? Ideally I’d like it to be equivalent of InvariantCultureIgnoreCase.
In other words, how do I make the output of this function case insensitive?
private byte[] ComputeHash(string s)
{
byte[] data = System.Text.Encoding.Unicode.GetBytes(s ?? string.Empty);
SHA1 sha = new SHA1CryptoServiceProvider(); // returns 160 bit value
return sha.ComputeHash(data);
}
If SHA isn’t possible, I might be able to make String.GetHashCode() work, but I don’t see a way to make that case insensitive either.
I'm betting this isn't possible. If its not, what are some work arounds?