Click here to Skip to main content
15,741,892 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to create a GUID from a string that looks like this "ZgEKpwQbNswAAAFgf2R4ugv.".

24-character string => Guid, AND Guid => 24-character string

The problem is that the string is 24-bytes array and to generate a GUID I need a 16-bytes array. The string is from a character collection of 64 characters, so the minimum representation of the 24-bytes string is 18-bytes array.

Is there a way tackle this issue?

What I have tried:

If you implement the folloowing code, you will find that the bytes array for the string is of 24-bytes and cannot be used to generate a guid.

string data = "ZgEKpwQbNswAAAFgf2R4ugv.";  
            byte[] databytes = Encoding.ASCII.GetBytes(data);  
            Guid g = new Guid(databytes); // not possible   
            byte[] reversedguid = g.ToByteArray();  
Updated 12-Apr-22 8:00am

You are going to have to go back to where you got the data from and ask there - it's not obvious what encoding was used to generate that string.
It looks like Base64, but that decodes to an 18 byte value:
66 01 0A A7 04 1B 36 CC 00 00 01 60 7F 64 78 BA 0B C0

Based on one sample of data, with no idea what the actual binary data should be it's not possible to be sure what to do with the value (GUIDs do have a format, but there are 5 different versions and without being able to "decode" the input first, we can't even tell which one it is!)
Share this answer
As it is stated, there is no way.
You should make a compromise. For instance, you may keep three characters in the string fixed (or computable from the other ones). Or you might accept that the same GUID is mapped to many strings.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900