What is a good way to convert a file path (URI) into a System.Guid? I'd like to minimize the possibility of a collision, but I'm happy with a reasonably unique hashing (probably never more than a few dozen/hundred items in the database)
+6
A:
There is no need. Hash URI with md5 or sha1 and that's all. GUIDs are not for hashing things. They meant to be created unique independently of everything else.
FractalizeR
2010-06-12 20:33:47
Appreciate the spanking, but I've got to retrofit these into a system which already depends on Guids. EDIT: ah, I see md5 creates a 128bit number, which equals a Guid. I can go from here I think.
David Rutten
2010-06-12 20:34:55
I am not sure, but I think there may be a collision with "natively generated" GUIDs this way if you generate a real lot of them
FractalizeR
2010-06-12 20:45:12
hi, I am interested in knowing what program OR how you would convert the URI to md5 hash? is there a utility somewhere in VS? thanks!
VoodooChild
2010-06-12 21:05:25
@VoodooChild, have a look at System.Security.Cryptography.MD5CryptoServiceProvider
David Rutten
2010-06-12 22:21:47
Look at the implementations of the v3 (MD5) and v5 (SHA-1) UUIDs in RFC 4122, http://www.ietf.org/rfc/rfc4122.txt uuid_create_md5_from_name and in Python, http://svn.python.org/view/python/trunk/Lib/uuid.py?view=markup
George V. Reilly
2010-06-15 20:12:15
If someone is asking how to hash something in .NET that's really useless to send him to RFCs...
FractalizeR
2010-06-16 07:11:56
+2
A:
If you have the option of a centralized registry/database, you could maintain a GUID <-> URL resolver and generate a new GUID for each URL you need. This would use GUIDs the way they are intended, minimizing probability of collision with natively-generated GUIDs.
Michael E
2010-06-12 20:51:18
Michael, excellent suggestion. I'll keep this in mind in case I run into issues with the md5 encryption.
David Rutten
2010-06-13 09:38:18