TensionDev.UUID.v8.CryptographicHash is a .NET library extending TensionDev.UUID with support for name-based UUID Version 8 using Cryptographic Hash Algorithms.
This project references the following documents for implementation.
- Support for three SHA-2 hash algorithms:
- SHA-256
- SHA-384
- SHA-512
- Strict RFC compliance for parsing and validation
dotnet add package TensionDev.UUID.v8.CryptographicHashusing TensionDev.UUID.v8.CryptographicHash;
// Generate a UUID using DNS namespace with SHA-256
Uuid uuid = SHA256.NewUUIDv8(UUIDNamespace.DNS, "www.contoso.com");
Console.WriteLine(uuid); // Example: 0b3e79a4-6f85-825a-a65d-fc78495c9381using TensionDev.UUID.v8.CryptographicHash;
// Generate a UUID using URL namespace with SHA-384
Uuid uuid = SHA384.NewUUIDv8(UUIDNamespace.URL, "https://www.contoso.com");
Console.WriteLine(uuid); // Example: 1a261a04-809b-8b96-b370-2cdfaa8dfb9cusing TensionDev.UUID.v8.CryptographicHash;
// Generate a UUID using OID namespace with SHA-512
Uuid uuid = SHA512.NewUUIDv8(UUIDNamespace.OID, "1.0.3166.1");
Console.WriteLine(uuid); // c05c49a2-ae23-83e9-913e-34dfe2751dc5using TensionDev.UUID.v8.CryptographicHash;
Uuid uuid = SHA512.NewUUIDv8(UUIDNamespace.X500, "/c=us/o=Sun/ou=People/cn=Rosanna Lee");
bool isValid = SHA512.IsUUIDv8(uuid);
Console.WriteLine(isValid); // true