I was asked by another developer recently that was struggling to find a way to provide a Guid that was somehow a hashed value of a given string. The idea was that for any provided string, it would always return the same Guid value. They weren’t concerned with duplicates as that was taken care of using some other set of business logic.

The best thing that came to mind that accomplished this was pushing the string through the MD5 crypto provider and then feeding it into the Guid constructor. The output from the provider is 16 bytes, which just so happens to be the matching array size that the Guid constructor hopes to receive.

Weirdly, neither him or any of the other developers on his team knew about this trick. So I figure it’s something that should be worth posting as it didn’t seem obvious to them, and I guess I should make use of this blog thing every once in a while given that I pay $10/month for it.