6
$\begingroup$

Basically what the title is; GUIDs are unique by design. If you run the GUID through SHA1 and then Base64 the hash, will the resulting string have the same guaranteed uniqueness as the GUID, or not?

$\endgroup$
11
$\begingroup$

Base64 provides a 1:1 transform from input to output (and back again if desired). So if you take a set of unique items and base64 encode all of them they will all be unique.

So the question becomes if you run a GUID through SHA1, will the resulting hash have the same uniqueness as the GUID?

The answer is practically - yes; theoretically not quite. Multiple inputs to SHA1 map to the same output, but in reality if your GUIDs are unique then there is negligible probability that there will ever be a collision leading to loss of uniqueness.

| improve this answer | |
$\endgroup$
1
$\begingroup$

Assuming no cosmetics, the length of a GUID is 32 bytes so better question would be "What's the collision probability of SHA1 with 32 bytes of input?"

I'm sure someone else will answer with the exact statistics but the answer to your question is yes, it's pretty unique (an attacker has a negligible probability of success). Note that I've completely ignored Base64 because it is reversible.

Edit: This question can provide some more insight

| improve this answer | |
$\endgroup$
  • 3
    $\begingroup$ The length of a GUID is 16 bytes. You can encode these bytes as a 32 byte hex string. $\endgroup$ – CodesInChaos May 25 '13 at 8:59
1
$\begingroup$

First note that GUIDs are not absolutely guaranteed to be unique. The early GUID constructions were supposed to be deterministically unique but this relied on clocks moving monotonically forwards and MAC addresses being deterministically unique. Later GUID versions gave up the deterministic uniqueness completely.

It is possible that two distinct GUIDs could hash to the same SHA1 hash but the chances of that happening in practice are much lower than the chances of a uniqueness failure of the underlying GUID generation system.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.