Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have created guid from a string using below code:
private Guid GetGuid(string input)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] inputBytes = Encoding.Default.GetBytes(input);
byte[] hashBytes = provider.ComputeHash(inputBytes);
Guid hashGuid = new Guid(hashBytes);
return hashGuid;
}
suppose i given input parameter "Arvind" and got guid like: 77f92c53-38af-42f6-8289-fddbd32f228d

now i want to convert this guid "77f92c53-38af-42f6-8289-fddbd32f228d" back to my original string which is "Arvind" . is there any way?

Thaks,
Arvind

What I have tried:

...........................................................
Posted
Updated 10-Apr-20 11:15am
Comments
Garth J Lancaster 9-Mar-17 7:29am    
MD5 is a one way hash - there is no way you can go back from "77f92c53-38af-42f6-8289-fddbd32f228d" to "Arvind"
Arvind Singh Baghel 9-Mar-17 7:42am    
Hi Garth is there any way to achieve "Arvind" to guid "77f92c53-38af-42f6-8289-fddbd32f228d" and then back "77f92c53-38af-42f6-8289-fddbd32f228d" to "Arvind" without MD5
Karthik_Mahalingam 9-Mar-17 11:49am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.
Arvind Singh Baghel 10-Mar-17 0:08am    
@Karthik your comment is not relevant to my query. please dont comment unnecessary things.
Karthik_Mahalingam 10-Mar-17 0:26am    
Hi Hrides,
you have posted a text to Grath, but he will not get notified through mail or in the notification icon unless you post using "reply" button,

you have posted the text using "Have a Question or Comment?" button.

its a tip for you to take care in future to get quick response from the user.

Thanks
karthik

1 solution

There is no way to reverse a hash operation (retrieve the original string from the hash). That is by intention and usually a requirement.

Howewer, it might be possible to retrieve it using a Brute-force attack - Wikipedia[^] or a Dictionary attack - Wikipedia[^].

For more information just search for something like "md5 reverse hash".
 
Share this answer
 
Comments
Arvind Singh Baghel 9-Mar-17 7:46am    
Hi Jochen is there any way to achieve "Arvind" to guid "77f92c53-38af-42f6-8289-fddbd32f228d" and then back "77f92c53-38af-42f6-8289-fddbd32f228d" to "Arvind" without MD5. i tried this
byte[] inputBytes = Encoding.Default.GetBytes("Arvind");
Guid hashGuid = new Guid(inputBytes);
but i am getting error System.ArgumentException: Byte array for GUID must be exactly 16 bytes long.
and i tried Guid hashGuid = new Guid("Arvind")
and getting error:
return hashGuid; System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
Jochen Arndt 9-Mar-17 8:36am    
A GUID is made of 16 bytes / 128 bits.
The string version Guid(string) is there to convert a valid string representation of a GUID to the numerical format.

To create a Guid from any string you can create a byte array from the string which contains at least 16 bytes (the array might be longer; then use a 16-byte subset).

Hash functions are the common way to do this. But with hash functions there is no mathematical solution to reverse the operation.

If you really need to get a GUID from a string just use the code points of the first 16 characters. If the string is too short, extent it repeating the input string:
"ArvindArvindArvind"

But this would not generate a Global Unique ID. So you would have an ID in the form of a GUID but not a real GUID.

This would of course als apply to your first try using a hash of "Arvind".

For such reasons, GUIDs are aften generated from seldom strings like full company or personal names combined with a datetime. Then there would be only a duplicate when another one generates the GUID using the same string at the same time with the same hash algorithm.

To nail it down:
A GUID should be a unique value. They are not generated repeatedly but once for a specific purpose and the one who generates it knows the initially used data.

It seems that you want to use a GUID for something else. Than don't use a GUID but something that matches your requirements.

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