-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) implementation based on RFC 4122 This will replaced all reference to System.Guid. Create UUIDv3.cs Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 3 (MD5 Namespace name-based). Relying on System.Security.Cryptography.MD5 for the hashing algorithm. Create UUIDv5.cs Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 5 (SHA-1 Namespace name-based). Relying on System.Security.Cryptography.SHA1 for the hashing algorithm.
- Loading branch information
Showing
17 changed files
with
1,140 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace TensionDev.UUID | ||
{ | ||
/// <summary> | ||
/// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 3 (MD5 namespace name-based). | ||
/// </summary> | ||
public class UUIDNamespace | ||
{ | ||
/// <summary> | ||
/// Namespace for Domain Name System | ||
/// </summary> | ||
public static Uuid DNS = new Uuid(0x6ba7b810, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8); | ||
/// <summary> | ||
/// Namespace for URLs | ||
/// </summary> | ||
public static Uuid URL = new Uuid(0x6ba7b811, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8); | ||
/// <summary> | ||
/// Namespace for ISO Object IDs (OIDs) | ||
/// </summary> | ||
public static Uuid OID = new Uuid(0x6ba7b812, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8); | ||
/// <summary> | ||
/// Namespace for X.500 Distinguished Names(DNs) | ||
/// </summary> | ||
public static Uuid X500 = new Uuid(0x6ba7b814, 0x9dad, 0x11d1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace TensionDev.UUID | ||
{ | ||
/// <summary> | ||
/// Class Library to generate Universally Unique Identifier (UUID) / Globally Unique Identifier (GUID) based on Version 3 (MD5 namespace name-based). | ||
/// </summary> | ||
public class UUIDv3 | ||
{ | ||
/// <summary> | ||
/// Initialises a new GUID/UUID based on Version 3 (MD5 namespace name-based) | ||
/// </summary> | ||
/// <returns>A new Uuid object</returns> | ||
public static Uuid NewUUIDv3(Uuid nameSpace, String name) | ||
{ | ||
Byte[] nsArray = nameSpace.ToByteArray(); | ||
Byte[] nArray = Encoding.UTF8.GetBytes(name); | ||
|
||
Byte[] buffer = new Byte[nsArray.Length + nArray.Length]; | ||
Buffer.BlockCopy(nsArray, 0, buffer, 0, nsArray.Length); | ||
Buffer.BlockCopy(nArray, 0, buffer, nsArray.Length, nArray.Length); | ||
|
||
Byte[] hash; | ||
using (MD5 md5 = MD5.Create()) | ||
{ | ||
hash = md5.ComputeHash(buffer); | ||
} | ||
|
||
Byte[] hex = new Byte[16]; | ||
|
||
hex[0] = hash[0]; | ||
hex[1] = hash[1]; | ||
hex[2] = hash[2]; | ||
hex[3] = hash[3]; | ||
|
||
hex[4] = hash[4]; | ||
hex[5] = hash[5]; | ||
|
||
hex[6] = (Byte)((hash[6] & 0x0F) + 0x30); | ||
hex[7] = hash[7]; | ||
|
||
hex[8] = (Byte)((hash[8] & 0x3F) + 0x80); | ||
hex[9] = hash[9]; | ||
|
||
hex[10] = hash[10]; | ||
hex[11] = hash[11]; | ||
hex[12] = hash[12]; | ||
hex[13] = hash[13]; | ||
hex[14] = hash[14]; | ||
hex[15] = hash[15]; | ||
|
||
Uuid Id = new Uuid(hex); | ||
|
||
return Id; | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.