Wondering which hashing algorithm I should be using to create primary keys from strings. Right now I’m using SHA-1.
In the past I’ve used SHA-256, although I have heard that 256 might be ‘overkill’ for my purposes. I’ve also heard some things about maybe using MD5, but I don’t know much about the pros and cons of that one.
Thanks!
Depends a lot on your use case: whether a malicious user can gain anything if finding a collision, for starters. There is a big difference between a hashing function and a cryptographically-secure hashing algorithm. I will assume your use case is a normal programming question.
MD5 is broken. Seeing how that has recently caused problems to hashing of dictionary keys in various languages, I would not use it for anything.
SHA-1 is more and more broken as time passes. Even though you may not need a cryptographically-secure algorithm, I would use SHA-256 unless the difference in performance is really significant, premature optimization being evil and all that.