Skip to content

This library allows you to convert Guid to 26-character long string using RFC 4648 Base32 encoding (ABCDEFGHIJKLMNOPQRSTUVWXYZ234567), it is URL-safe, case-insensitive. You can also decode string back to Guid.

License

pavelsource/shorter-guid

Repository files navigation

SourceExpress.ShorterGuid

This library contains extension methods to generate a 26-character long string from the Guid, which is URL-safe and case-insensitive! It uses Base32 encoding with the following character set: ABCDEFGHIJKLMNOPQRSTUVWXYZ234567.

Inspired by CSharpVitamins.ShortGuid library which uses Base64 encoding and produces a 22-character long string, however it is case-sensitive!

Available on NuGet. To install, run the following command in the Package Manager Console:

PM> Install-Package SourceExpress.ShorterGuid

The Gist

It takes a standard guid like this:

7ff2d2cb-1e1d-41cc-b478-32adb96082bd

and shortens it to a smaller string like this:

ZPJPE7Y5D3GEDNDYGKW3SYECXU or zpjpe7y5d3gedndygkw3syecxu


Using the ShorterGuid

The ShorterGuid provides two extension methods for Guid class:

var guid = Guid.NewGuid();  // 7ff2d2cb-1e1d-41cc-b478-32adb96082bd
var shorterGuid = guid.ToShorterString(); // ZPJPE7Y5D3GEDNDYGKW3SYECXU
var guid = Guid.NewGuid();  // 7ff2d2cb-1e1d-41cc-b478-32adb96082bd
var shorterGuid = guid.ToLowerShorterString(); // zpjpe7y5d3gedndygkw3syecxu

If you need to get Guid from the ShorterGuid string, you can do that using second extension method:

var shorterGuid = "ZPJPE7Y5D3GEDNDYGKW3SYECXU"; // or "zpjpe7y5d3gedndygkw3syecxu"
var guid = shorterGuid.FromShorterString(); // 7ff2d2cb-1e1d-41cc-b478-32adb96082bd

Methods contain some internal error handling like wrong character or incorrect length of the ShorterGuid. See test project for more details.

About

This library allows you to convert Guid to 26-character long string using RFC 4648 Base32 encoding (ABCDEFGHIJKLMNOPQRSTUVWXYZ234567), it is URL-safe, case-insensitive. You can also decode string back to Guid.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages