c# - How can I generate a GUID for a string? -
There is a problem generating the GUID for the string - for example:
Guid G = New Good ("Mehr");
How do I calculate the GUID for "Mehr"
? I'm getting an exception.
This thread is quite old but in this way we solve this problem:
Since GUID is the arbitrary 16bytes or 128bits from the .NET framework, you can calculate the grid from the concrete string by making a hash function a 16-byte hash and after passing the result grid the manufacturer.
We have decided to use the MD5 hash function and an example code can look like this:
string input = "asdfasdf"; (Byte [] hash = MD5 using MD5 md5 = MD5.Create ()). Compute hash (encoding. default.net); Guid Results = New Guid (hash); }
Please note that this grid generation has some flaws such as it depends on the quality of the hash function! If your hash function generates the same hash for the many strings you use, it is going to affect the behavior of your software.
Here is a list of the most popular hash functions that produces 128bit digest:
- RIPEMD (probability of collision: 2 ^ 18) < Li> MD4 (possibility of collision: to ensure)
- MD5 (probability of collision: 2 ^ 20.96)
Please note that one other Use the hash functions that produce large distances and only shrink them so to use the new hash function The Mart may be. To list some:
- SHA-1
- SHA-2
- SHA-3
Today (August 2013) 160bit SHA1 hash can be considered a good option.
Comments
Post a Comment