Creating a GUID with a Prefix Given

I wonder if there is a way to generate valid GUID / UUIDs, where the first part (or any part) is the user-selected prefix.

Ie, the GUID is in the format AAAAAAAA-BBBB-UDP-DDDD-DDDDDDDDDDDDD, and I want to set any part to a predefined value (ideally AAA). The goal is for the GUIDs to remain globally unique, but they should not be cryptographically secure.

+2
c # guid
source share
6 answers

Sorry, you want too much from a GUID. To summarize from your question and your own answer / update, you want it to be

  • 1 - GUID
  • 2 do not encounter any other GUID (globally unique)
  • 3 Ignore the standard when interpreting the first bits using the reserved value.
  • 4 Use your personal scheme for the rest of the bits.

This is not possible, proof: If it were possible, I could create a GUID G1, and you could create another GUID G2. Since we both ignore the standard and use the same reserved prefix, and my personal scheme for the other bits is out of your control, my GUID G1 may interfere with your GUID G2. Fuzzy match of GUIDs should adhere to the GUID standard.

Collision avoidance mechanisms are truly inherently confidential. If I randomly generate a G1 GUID, I can guarantee that the random GUID is unique if two conditions are true:

  • 1 It is included in a subset of the GUIDs under my control and
  • 2 I have not generated a GUID before.

For GUIDs outside a subset of your control, you cannot guarantee (2). But how do you assign nonoverlapping GUID subsets to one person? Using a MAC network adapter is a simple and efficient way. Other means are possible. But in any case, the mere existence of such a subset is hidden privacy. It must belong to someone, and I must be able to determine whether it is me or someone else. It's a lot harder to prove whether two random GUIDs G1 and G2 belong to the same subset (i.e. a person), but the current schemes (which you mind) do not try to hide it.

+4
source share

Hmmm ... so, will you mostly like the 12-byte GUID? Since, as soon as you remove the uniqueness of the first 4 bytes (your AAA), you have broken the existing algorithm - you will need to come with your own algorithm.

In accordance with the relevant RFC, the GUID format is divided into:

UUID = time-low "-" time-mid "-" time-high-and-version "-" clock-seq-and-reserved clock-seq-low "-" node time-low = 4hexOctet time-mid = 2hexOctet time-high-and-version = 2hexOctet clock-seq-and-reserved = hexOctet clock-seq-low = hexOctet node = 6hexOctet hexOctet = hexDigit hexDigit hexDigit = "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" / "a" / "b" / "c" / "d" / "e" / "f" / "A" / "B" / "C" / "D" / "E" / "F" 

The only static data in it are the version (4 bits) and the reserved / variant (2-3 bits). I don’t see them accepting any “user-defined” versions, but I would say that in the foreseeable future you will be safe if you use 1111 as your version identifier. Existing versions are given in Section 4.1.3, but so far only 5 have been defined ... this gives you 11 more fixes before the collision.

So, if you can live with 6 or 7 bit differences, the combination of Guid.NewGuid (). ToByteArray () and creating a new Guid after you start bitcoin.

+5
source share

It is not possible to create a GUID / UUID where the first (or any part) part is a user-selected prefix, while you can write your own function to create a unique identifier with the same number (36/38) characters ..

+2
source share

You can simply create a Guid and change the prefix as you imagine it. You saw this in an OS project where the same question was thrown and resolved by creating so many hints until the desired prefix (ugh!) Matches.

Guid g = Guid.NewGuid(); string gs = g.ToString(); Guid f = new Guid(string.Format("{0}-{1}", "AAAAAAAA", gs.Substring(gs.IndexOf('-') + 1)));

I do not like it, but it works.

What bothered me from the other posts on this issue was that the manual should be globally unique, in all cases it is not, it has enough space to create unique contours, but nothing is guaranteed for the globally unique. Even time is not taken into account when generating guid.

0
source share

Thanks. My problem with these attempts is that they are not guaranteed to be globally unique, as noted . I was wondering if there is another algorithm that generates unique GUIDs. I remember that there used to be implementations that used the timestamp and / or the MAC address of the NIC, but they are no longer used because they are not cryptographic and / or there are privacy issues.

Interesting: if I just make up, should I be okay? According to Wikipedia :

From one to the three most significant bits of the second byte in Data 4 define a variant of the GUID type:

Pattern description
0 Backward compatible with network computing system
10 standard
110 Backward compatible with the Microsoft object model; this includes a GUID for important interfaces such as IUnknown and IDispatch.
111 Reserved for future use.

The most significant four bits of Data3 determine the version number and the algorithm used.

So, if I create something in Data3 / Data4, I would usually create my own implementation, which should not run into any other GUID, but, of course, there is always a risk associated with this, so before I I will do this, I wanted to check if there is an older / no longer used algorithm that generates true unique identifiers.

0
source share

I recently had a similar need - I need a GUID that was:

  • created by standard guid algorithms, and therefore has the chance to be globally unique.
  • has a specific prefix.

As you could imagine, I was doing what I shouldn't.

You mentioned in one of your comments that you can simply run the GUID generator until it stumbles upon guid with the prefix you need. This is the tactic I took. Here is the code:

 using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string target_prefix = "dead"; while (true) { Guid g = Guid.NewGuid(); string gs = g.ToString(); if (gs.Substring(0, target_prefix.Length) == target_prefix) { Console.WriteLine("Match: " + gs); } else { //Console.WriteLine("Mismatch: " + gs); } } } } } 

For smaller prefixes, it matches more quickly. I am sure that it is 16 times for each digit of the target prefix.

0
source share

All Articles