Skip to content

Instantly share code, notes, and snippets.

@jrgcubano
Created March 3, 2015 23:01
Show Gist options
  • Save jrgcubano/d383b16d7a3f00213e8e to your computer and use it in GitHub Desktop.
Save jrgcubano/d383b16d7a3f00213e8e to your computer and use it in GitHub Desktop.
Generate guid from custom string
// 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