How to generate deterministic GUID/UUIDs v3/v5 in C# having both namespace and name as strings (according to RFC4122, you need to provide namespace as GUID and name as string) provided to function, so i would like to provide two strings instead guid for namespace and string for name and have always same GUID/UUID for string for namespace and for string for name. Is hashing namespace string with MD5/SHA1 and making new Guid by Guid(byte[]) constructor a safe way to acomplish this, so i could further provide it to function ? I am NOT asking about parsing guid-a-like string to namespace by Guid.TryParse(), but converting any string to guid namespace to further provide it for below function, but having it deterministic as well. According to https://github.com/Faithlife/FaithlifeUtility/blob/master/src/Faithlife.Utility/GuidUtility.cs and RFC 4122 this is how you should create GUID given the GUID namespace and string name/any string.
/// <summary>
/// Creates a name-based UUID using the algorithm from RFC 4122 §4.3.
/// </summary>
/// <param name="namespaceId">The ID of the namespace.</param>
/// <param name="nameBytes">The name (within that namespace).</param>
/// <param name="version">The version number of the UUID to create; this value must be either
/// 3 (for MD5 hashing) or 5 (for SHA-1 hashing).</param>
/// <returns>A UUID derived from the namespace and name.</returns>
public static Guid Create(Guid namespaceId, byte[] nameBytes, int version)
{
if (version != 3 && version != 5)
throw new ArgumentOutOfRangeException(nameof(version), "version must be either 3 or 5.");
// convert the namespace UUID to network order (step 3)
byte[] namespaceBytes = namespaceId.ToByteArray();
SwapByteOrder(namespaceBytes);
// compute the hash of the namespace ID concatenated with the name (step 4)
byte[] data = namespaceBytes.Concat(nameBytes).ToArray();
byte[] hash;
using (var algorithm = version == 3 ? (HashAlgorithm) MD5.Create() : SHA1.Create())
hash = algorithm.ComputeHash(data);
// most bytes from the hash are copied straight to the bytes of the new GUID (steps 5-7, 9, 11-12)
byte[] newGuid = new byte[16];
Array.Copy(hash, 0, newGuid, 0, 16);
// set the four most significant bits (bits 12 through 15) of the time_hi_and_version field to the appropriate 4-bit version number from Section 4.1.3 (step 8)
newGuid[6] = (byte) ((newGuid[6] & 0x0F) | (version << 4));
// set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively (step 10)
newGuid[8] = (byte) ((newGuid[8] & 0x3F) | 0x80);
// convert the resulting UUID to local byte order (step 13)
SwapByteOrder(newGuid);
return new Guid(newGuid);
}