Reputation: 9721
I am trying to create a function that takes an arbitrary string as input and creates a GUID based on that string. The GUID's format should be ideally the GUID
struct from objbase.h
, but it's not that important. What is important is that the function is deterministic but always (or close enough to always) creates a different GUID for different strings.
What kind of algorithm could I use to do that? I've thought about bit operations on the contents of the string but I would appreciate some direction.
Upvotes: 1
Views: 1546
Reputation: 6850
What about computing an MD5 hash of the string and treating it as if it were a GUID? GUIDs and MD5 hashes are both 128-bit values.
Upvotes: 2
Reputation: 11557
Check the specifications for UUID version 3 and 5:
In essence, you compute MD5 (or SHA-1) of your string and store the results verbatim in a 128-bit UUID. For SHA-1, you need to truncate the result, as SHA-1 returns 160-bits.
Upvotes: 1
Reputation: 1058
You can hash the string and then use the first 16 bytes of the hash to create a GUID (http://msdn.microsoft.com/en-us/library/90ck37x3.aspx)
Upvotes: 1