How can I generate a GUID for a string?

后端 未结 9 1736
Happy的楠姐
Happy的楠姐 2020-12-02 14:14

I am having a problem generating a GUID for a string - for example:

Guid g = New Guid(\"Mehar\");

How can I compute a GUID for \"Meha

9条回答
  •  隐瞒了意图╮
    2020-12-02 14:54

    If op's intent is to create a UUID (Guid) from a string hash of some sort (MD5, SHA-1, et.c.), I found this very similar question with this great answer:

    https://stackoverflow.com/a/5657517/430885

    It has a link to a github-snippet based on RFC 4122 §4.3, that will create a Guid from a string and a namespace (which you can choose for yourself to guarantee against collisions from outside environments).

    Direct link to the snippet: https://github.com/LogosBible/Logos.Utility/blob/master/src/Logos.Utility/GuidUtility.cs

提交回复
热议问题