Generate UUID v3

Generate a name-based UUID v3 using MD5 hashing of namespace and name.

Code

Utilities
ns=$(echo -n "${namespace//-/}" | sed 's/../\\x&/g')
hash=$(printf "${ns}${name}" | md5sum | cut -c1-32)
v=$(printf '%x' $(( (0x${hash:12:2} & 0x0f) | 0x30 )))${hash:14:2}
c=$(printf '%x' $(( (0x${hash:16:2} & 0x3f) | 0x80 )))${hash:18:2}
echo "${hash:0:8}-${hash:8:4}-${v}-${c}-${hash:20:12}"

Parameters

Namespace UUID (use DNS, URL, OID, or X500 namespace).

Name to hash within the namespace.

Server

More Bash Snippets