Created
March 3, 2015 23:01
-
-
Save jrgcubano/d383b16d7a3f00213e8e to your computer and use it in GitHub Desktop.
Generate guid from custom string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Found this snippet to be useful when using unique identifier in a database for federated distribution | |
public static Guid ToGuid(string src) | |
{ | |
byte[] stringbytes = Encoding.UTF8.GetBytes(src); | |
byte[] hashedBytes = new System.Security.Cryptography | |
.SHA1CryptoServiceProvider() | |
.ComputeHash(stringbytes); | |
Array.Resize(ref hashedBytes, 16); | |
return new Guid(hashedBytes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment