Giter Site home page Giter Site logo

tomasekeli / deterministic-guid-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from informatievlaanderen/deterministic-guid-generator

0.0 1.0 0.0 1009 KB

Create a deterministic GUID based on namespace Guid, a string and an optional version.

Home Page: https://www.nuget.org/packages/Be.Vlaanderen.Basisregisters.Generators.Guid.Deterministic/

License: MIT License

F# 17.35% Shell 2.79% C# 79.86%

deterministic-guid-generator's Introduction

Be.Vlaanderen.Basisregisters.Generators.Deterministic Build Status

Goal

Create a deterministic GUID based on a namespace, a string and an optional version.

Although a new GUID is typically created in order to provide a unique ID, there are occasions when it’s useful for two different systems to generate the same GUID independently. RFC 4122 provides an algorithm for deterministic creation of a GUID based on a namespace ID (itself a GUID) and a name within that namespace. These name-based GUIDs will never collide with GUIDs from other sources (e.g., Guid.NewGuid), and have a very (very) small chance of colliding with other name-based GUIDs. As per section 4.3:

  • The UUIDs generated at different times from the same name in the same namespace MUST be equal.
  • The UUIDs generated from two different names in the same namespace should be different (with very high probability).
  • The UUIDs generated from the same name in two different namespaces should be different with (very high probability).
  • If two UUIDs that were generated from names are equal, then they were generated from the same name in the same namespace (with very high probability).

Because .NET doesn’t provide a way to create these GUIDs, it’s tempting to create a custom solution (e.g., using a MD5 hash as a GUID, because it has the same number of bytes), but because that doesn’t follow the rules of GUID creation, it’s not guaranteed to be unique with respect to other GUIDs.

Usage

Determine a namespace for your use case, this is just a random GUID you can store somewhere.

Using Deterministic.Create you can now pass in the namespace and a value and it will always return the same GUID.

By default a version 5 GUID is created.

var namespaceGuid = new Guid("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
var value = "hello.example.com";
var deterministicGuid = Deterministic.Create(namespaceGuid, value);

A version 3 GUID uses MD5 to compute a hash of the namespace and name.

var namespaceGuid = new Guid("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
var value = "hello.example.com";
var version = 5;
var deterministicGuid = Deterministic.Create(namespaceGuid, value, version);

A version 5 GUID uses SHA1 to compute a hash of the namespace and name.

var namespaceGuid = new Guid("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
var value = "hello.example.com";
var version = 5;
var deterministicGuid = Deterministic.Create(namespaceGuid, value, version);

License

MIT License

Credits

Languages & Frameworks

  • .NET Core - MIT
  • .NET Core Runtime - CoreCLR is the runtime for .NET Core. It includes the garbage collector, JIT compiler, primitive data types and low-level classes. - MIT
  • .NET Core APIs - CoreFX is the foundational class libraries for .NET Core. It includes types for collections, file systems, console, JSON, XML, async and many others. - MIT
  • .NET Core SDK - Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI. - MIT
  • Roslyn and C# - The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs. - Apache License 2.0
  • F# - The F# Compiler, Core Library & Tools - MIT
  • F# and .NET Core - F# and .NET Core SDK working together. - MIT

Libraries

  • Paket - A dependency manager for .NET with support for NuGet packages and Git repositories. - MIT
  • FAKE - "FAKE - F# Make" is a cross platform build automation system. - MIT
  • xUnit - xUnit.net is a free, open source, community-focused unit testing tool for the .NET Framework. - Apache License 2.0
  • Shouldly - Should testing for .NET - the way Asserting Should be! - BSD
  • Faithlife.Utility - Common .NET utility code in use at Faithlife - MIT

Tooling

Flemish Government Libraries

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.