UUID ( Universally unique identifiers ) : UUID Version 3 & UUID Version 5














































UUID ( Universally unique identifiers ) : UUID Version 3 & UUID Version 5




__________ UUID version 3 and 5 __________


The UUIDs version 3 and 5 are produced by hashing a string using hast function ( MD5 for version 3 and SHA-1 for version 5), and because hashing is deterministic, the output is as unique as the input.

Version 3 or 5 UUID meant for generating UUIDs from "names", we can use name and namespace to create a series of unique UUIDs. In simple words version, 3 and  5 UUIDs is nothing but hashing namespace identifier with a name.

We are using hash function to combine a namespace value with "name" ( DNS hostnames, URLs, object ids, etc. ) to generate a UUID.

Collisions here are only possible if the underlying hash function also has a collision.

Version-3 and version-5 UUIDs have the property that the same namespace and name will map to the same UUID. However, neither the namespace nor name can be determined from the UUID, even if one of them is specified, except by brute-force search.

RFC 4122 recommends version 5 (SHA-1) over version 3 (MD5) and warns against use of UUIDs of either version as security credentials.


The UUID module defines the following namespace identifiers to use with UUID version 3 or version 5 :

  • UUID.NAMESPACE_DNS means a fully qualified domain name. For example, http://pynative.com.
  • UUID.NAMESPACE_URL When this namespace is specified, It means it is a URL.
  • UUID.NAMESPACE_OID When this namespace is specified, the name string is an ISO OID.
  • UUID.NAMESPACE_X500 When this namespace is specified, the name string is an X.500 DN in DER or a text output format.


UUID version 3 and version 5 important points :

  • The UUIDs generated at a different time using the same namespace and same name are equal.
  • The unique Ids generated from two different names in the same namespace are different.
  • The UUIDs generated from the same name in two different namespaces are different.


Example 1 : Generate a UUID 3 and UUID 5 using the different hostname and same namespace.

Code -


Output -



Example 2 :

Code -


Output -


NOTE - The UUID value for a given name in a namespace is always the same, no matter when or where it is calculated.


Example 3 : Generate a UUID 3 and UUID 5 using a different namespace and constant name.

Code -


Output -


NOTE - Values for the same name in different namespaces are different.

-

Previous Articles :

Introduction to UUID and UUID format

UUID Version 1

Next Articles :

UUID Version 4

When to use UUID

Safe and Unsafe UUID


Comments