![]() |
VOOZH | about |
dotnet add package Hashids.net --version 1.7.0
NuGet\Install-Package Hashids.net -Version 1.7.0
<PackageReference Include="Hashids.net" Version="1.7.0" />
<PackageVersion Include="Hashids.net" Version="1.7.0" />Directory.Packages.props
<PackageReference Include="Hashids.net" />Project file
paket add Hashids.net --version 1.7.0
#r "nuget: Hashids.net, 1.7.0"
#:package Hashids.net@1.7.0
#addin nuget:?package=Hashids.net&version=1.7.0Install as a Cake Addin
#tool nuget:?package=Hashids.net&version=1.7.0Install as a Cake Tool
A small .NET package to generate YouTube-like IDs from numbers.
It converts numbers like 347 into strings like yr8, or array of numbers like [27, 986] into 3kTMd. You can also decode those ids back. This is useful in bundling several parameters into one, hiding actual IDs, or simply using them as short string IDs.
int and long)NOTE: This is NOT a true cryptographic hash, since it is reversible
Install the package with NuGet
Install-Package hashids.net
using HashidsNet;
You can pass a unique salt value so your hashes differ from everyone else's. I use "this is my salt" as an example.
var hashids = new Hashids("this is my salt");
var hash = hashids.Encode(12345);
hash is now going to be:
NkK9
If your id is stored as a Int64 you need to use "EncodeLong".
var hashids = new Hashids("this is my salt");
var hash = hashids.EncodeLong(666555444333222L);
hash is now going to be:
KVO9yy1oO5j
Notice during decoding, same salt value is used:
var hashids = new Hashids("this is my salt");
numbers = hashids.Decode("NkK9");
numbers is now going to be:
[ 12345 ]
var hashids = new Hashids("this is my salt");
numbers = hashids.DecodeLong("KVO9yy1oO5j");
numbers is now going to be:
[ 666555444333222L ]
By default, Decode and DecodeLong will return an array. If you need to decode just one id you can use the following helper functions:
var hashids = new Hashids("this is my pepper");
number = hashids.DecodeSingle("NkK9");
number is now going to be:
12345
var hashids = new Hashids("this is my pepper");
if (hashids.TryDecodeSingle("NkK9", out int number)) { // Decoding hash successfull. }
number is now going to be:
12345
You can handle the exception to see what went wrong with the decoding:
var hashids = new Hashids("this is my pepper");
try
{
number = hashids.DecodeSingle("NkK9");
}
catch (NoResultException) { // Decoding the provided hash has not yielded any result. }
number is now going to be:
12345
var hashids = new Hashids("this is my pepper");
number = hashids.DecodeSingleLong("KVO9yy1oO5j");
number is now going to be:
666555444333222L
var hashids = new Hashids("this is my pepper");
if (hashids.TryDecodeSingleLong("NkK9", out long number)) { // Decoding hash successfull. }
number is now going to be:
666555444333222L
var hashids = new Hashids("this is my pepper");
try
{
number = hashids.DecodeSingleLong("KVO9yy1oO5j");
}
catch (NoResultException) { // Decoding the provided hash has not yielded any result. }
number is now going to be:
666555444333222L
Decoding will not work if salt is changed:
var hashids = new Hashids("this is my pepper");
numbers = hashids.Decode("NkK9");
numbers is now going to be:
[]
var hashids = new Hashids("this is my salt");
var hash = hashids.Encode(683, 94108, 123, 5);
hash is now going to be:
aBMswoO2UB3Sj
var hashids = new Hashids("this is my salt");
var numbers = hashids.Decode("aBMswoO2UB3Sj")
numbers is now going to be:
[ 683, 94108, 123, 5 ]
Here we encode integer 1, and set the minimum hash length to 8 (by default it's 0 -- meaning hashes will be the shortest possible length).
var hashids = new Hashids("this is my salt", 8);
var hash = hashids.Encode(1);
hash is now going to be:
gB0NV05e
var hashids = new Hashids("this is my salt", 8);
var numbers = hashids.Decode("gB0NV05e");
numbers is now going to be:
[ 1 ]
Here we set the alphabet to consist of: "abcdefghijkABCDEFGHIJK12345"
var hashids = new Hashids("this is my salt", 0, "abcdefghijkABCDEFGHIJK12345")
var hash = hashids.Encode(1, 2, 3, 4, 5)
hash is now going to be:
Ec4iEHeF3
The primary purpose of hashids is to obfuscate ids. It's not meant or tested to be used for security purposes or compression. Having said that, this algorithm does try to make these hashes unguessable and unpredictable:
var hashids = new Hashids("this is my salt");
var hash = hashids.Encode(5, 5, 5, 5);
You don't see any repeating patterns that might show there's 4 identical numbers in the hash:
1Wc8cwcE
Same with incremented numbers:
var hashids = new Hashids("this is my salt");
var hash = hashids.Encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
hash will be :
kRHnurhptKcjIDTWC3sx
var hashids = new Hashids("this is my salt");
hashids.Encode(1); // => NV
hashids.Encode(2); // => 6m
hashids.Encode(3); // => yD
hashids.Encode(4); // => 2l
hashids.Encode(5); // => rD
var hashids = new Hashids("this is my salt");
var hash = hashids.EncodeHex("DEADBEEF");
hash is now going to be:
kRNrpKlJ
var hashids = new Hashids("this is my salt");
var hex = hashids.DecodeHex("kRNrpKlJ");
hex is now going to be:
DEADBEEF
v.1.7.0
netstandard2.0, net6.0, net7.0.v.1.6.1
v.1.6.0
v1.5.0
net461 target.readonly and Span<T> usage.System.Memory to replace internal ReadOnlySpan<T> class.1.4.1
Microsoft.Extensions.ObjectPool with internal implementation.1.4.0
net461, net5.0, netstandard2.01.3.0
1.2.2
1.2.1
1.2.0Added
1.1.2
1.1.1
1.1.0
long via new functions to not introduce breaking changes.
EncodeLong for encodes.DecodeLong for decodes.IHashids for people who want an interface to work with.1.0.1
1.0.0
Several public functions marked obsolete and renamed versions added, to be more appropriate:
Encrypt() changed to Encode()Decrypt() changed to Decode()EncryptHex() changed to EncodeHex()DecryptHex() changed to DecodeHex()Hashids was designed to encode integers, primary ids at most. We've had several requests to encrypt sensitive data with Hashids and this is the wrong algorithm for that. So to encourage more appropriate use, encrypt/decrypt is being "downgraded" to encode/decode.
0.3.4
0.3.3
EncryptHex and DecryptHex0.1.4
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Hashids.net:
| Package | Downloads |
|---|---|
|
Apprio.Enablement.Platform
Package Description |
|
|
Apprio.Enablement.Business.Encounters
Package Description |
|
|
SFA.DAS.Encoding
Encode and Decode sensitive values, reads parameters from configuration. |
|
|
PackUtils
Many utilities like: enumeration, hash, json (extension newtonsoft), regex, signature, string, uri, dictionary, etc |
|
|
ShiftSoftware.ShiftEntity.Model
Package Description |
Showing the top 4 popular GitHub repositories that depend on Hashids.net:
| Repository | Stars |
|---|---|
|
SparkDevNetwork/Rock
An open source CMS, Relationship Management System (RMS) and Church Management System (ChMS) all rolled into one.
|
|
|
neozhu/visitormanagement
helps in managing visitors visiting the institutions for various reasons. It allows visitors to check-in digitally to eliminate the tedious registeration and other paperwork. Additionally, it also keeps a track of every individual inside the campus and their timings. Institutions has guards who enter their detail in some notebooks to keep a log which are practically impossible to reconcile. It is really unpleasent and hectic for visitor to stand at the gate and give details about the visit. To ease the process of registeration, Entry-In, Entry-Out, time tracking and logging the history, this VMS can be of great use!!
|
|
|
Anapher/Strive
Open source video conferencing platform
|
|
|
Xabaril/AspNetCore.Hashids
Not predictable ids library for ASP.NET Core APIs.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.7.0 | 5,991,373 | 3/17/2023 |
| 1.6.1 | 2,177,131 | 6/2/2022 |
| 1.6.0 | 60,015 | 5/22/2022 |
| 1.5.0 | 300,470 | 4/2/2022 |
| 1.4.1 | 1,070,393 | 7/3/2021 |
| 1.4.0 | 164,570 | 5/4/2021 |
| 1.3.0 | 3,141,535 | 10/29/2019 |
| 1.2.2 | 2,990,119 | 9/14/2016 |
| 1.2.1 | 10,014 | 9/10/2016 |
| 1.2.0 | 13,336 | 9/2/2016 |
| 1.2.0-rc | 2,600 | 9/2/2016 |
| 1.1.2 | 80,563 | 9/9/2015 |
| 1.1.1 | 12,444 | 8/29/2015 |
| 1.1.0 | 8,422 | 6/29/2015 |
| 1.0.1 | 193,825 | 4/25/2015 |
| 1.0.0 | 18,381 | 9/14/2014 |
| 0.3.4 | 3,734 | 9/14/2014 |
| 0.3.3 | 4,182 | 4/22/2014 |
| 0.1.4 | 7,429 | 12/20/2012 |