(Also MD5 is considered cryptographically broken, and SHA1 is on its last legs, so don't use this to verify data that needs to be "very secure"). Only 128-bits are available and 5 bits are used to specify the type, so all of the hash bits don't make it into the UUID. Type 3 UUIDs use MD5 and type 5 UUIDs use SHA1. Roughly speaking, a type 3 or type 5 UUID is generated by hashing together a namespace identifier with a name. Name and namespace can be used to create a hierarchy of (very probably) unique UUIDs. The name is just the text you want to have appended to the namespace, then hashed, and stuffed into a UUID: uuid = NameToUUID('8e884ace-bee4-11e4-8dfc-aa07a5b093db', 'screwdriver') The name is a string of arbitrary length. ![]() 1: UUID Namespace_RectalForeignExtractedObject = '8e884ace-bee4-11e4-8dfc-aa07a5b093db' It can be one of the pre-defined ones, or you can make up your own, e.g. The namespace is either a UUID in string representation or an identifier for internally pre-defined namespace UUIDs (currently known are "ns:DNS", "ns:URL", "ns:OID", and "ns:X500"). Now you can have calls: uuid = NameToUUID(Namespace_DNS, 'uuid = NameToUUID(Namespace_DNS, 'uuid = NameToUUID(Namespace_URL, '') įor version 3 and version 5 UUIDs the additional command line arguments namespace and name have to be given. (Note: the endian-ness of your system can affect indices of the above bytes) set high-nibble to 5 to indicate type 5 Copy first 16-bytes of the hash into our Uuid result Note: All code on stackoverflow is public domain - no attribution required.īyte hash = sha1(NamespaceUUID.ToBytes() + Name.ToBytes()) ![]() Now that you have a function that generates a so-called Name, you can have the function (in pseudo-code): UUID NameToUUID(UUID NamespaceUUID, String Name) The basic gist is to only take the first 128 bits, stuff a 5 in the type record, and then set the first two bits of the clock_seq_hi_and_reserved section to 1 and 0, respectively. StackOverflowUrlUUID = sha1(Namespace_URL + "") So, you could hash together: StackOverflowDnsUUID = sha1(Namespace_DNS + "") The UUID RFC pre-defines four namespaces for you: You prefix your string with a so-called namespace to prevent name conflicts. You're probably wondering what is it that I'm supposed to hash. ╰─low nibble is set to 5, to indicate type 5 ⭡ ⬑first two bits set to 1 and 0, respectively ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |