Friday, June 19, 2009

Generating strong repeatable GUIDs

In recent weeks I've had the problem of wanting to generate GUIDs that are distinct, but are repeatable -- in particular for things like COM class UIDs, and for installer component IDs, for a project using a lot of generated code.

So this is what I did in part of my build scripts (note, this is not totally RFC 4122 compliant, but it suffices in practice)

The input is the individual name of the thing I'm generating, concatenated with a constant GUID string used as a salt. The ToUpperInvariant is there to permit WiX to be run in pedantic mode.

Yes, it's exactly as vulnerable to hash collisions as MD5 -- but then my input is not maliciously aiming at such.

Later:-- or you could just use

but that makes the RFC 4122 guid-for-salt explicit for you.

No comments :