ArchSoft.HashId
1.0.1
dotnet add package ArchSoft.HashId --version 1.0.1
NuGet\Install-Package ArchSoft.HashId -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ArchSoft.HashId" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ArchSoft.HashId" Version="1.0.1" />
<PackageReference Include="ArchSoft.HashId" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ArchSoft.HashId --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ArchSoft.HashId, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ArchSoft.HashId@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ArchSoft.HashId&version=1.0.1
#tool nuget:?package=ArchSoft.HashId&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ArchSoft.HashId
A .NET library for generating deterministic unique identifiers based on SHA256 hash. Ideal for creating primary keys, record checksums, and data comparison.
π DocumentaΓ§Γ£o em PortuguΓͺs (Brazilian Portuguese)
π Installation
dotnet add package ArchSoft.HashId
β¨ Features
- π SHA256 Hash - Secure cryptographic algorithm
- π― Deterministic - Same inputs always generate the same hash
- π§Ή Smart Normalization - Removes accidental variations (accents, extra spaces, casing)
- π Culture Invariant - Consistent formatting regardless of system culture
- β‘ High Performance - Optimized for .NET 8+
- π‘οΈ Safe - Protection against ReDoS and overflows
π Use Cases
- Derived Primary Keys - Generate unique IDs from composite data
- Record Checksums - Detect changes in records
- Deduplication - Identify duplicate records
- Data Synchronization - Compare records between systems
- Cache Keys - Deterministic cache keys
π» Basic Usage
Simple Example
using ArchSoft.HashId;
// Generate hash from a string
string hash = HashId.GenerateNormalized("John Doe");
// Result: "3F2A8B..." (SHA256 hash in hexadecimal)
Multiple Fields
// Generate hash from multiple fields (automatically concatenated)
var hash = HashId.GenerateNormalized(
"John Doe",
DateTime.Parse("1990-05-15"),
12345.67m
);
With and Without Normalization
// With normalization (recommended for user data)
// Removes accents, extra spaces, converts to lowercase
string hash1 = HashId.GenerateNormalized(" John Doe ");
string hash2 = HashId.GenerateNormalized("john doe");
// hash1 == hash2 β
// Without normalization (for controlled data)
string hash3 = HashId.GenerateUnnormalized("John Doe");
string hash4 = HashId.GenerateUnnormalized("john doe");
// hash3 != hash4
π§ Supported Types
Automatic normalization works with:
| Type | Normalization |
|---|---|
string |
Removes accents, extra spaces, trim, lowercase |
decimal |
Invariant format: 0.################ |
double |
Invariant format: 0.################ |
float |
Invariant format: 0.################ |
DateTime |
Converts to UTC: yyyy-MM-ddTHH:mm:ss |
DateTimeOffset |
Uses the UtcDateTime representation: yyyy-MM-ddTHH:mm:ss |
bool |
true or false (lowercase) |
Enum |
Enum value name in lowercase |
π Advanced Examples
Primary Key for Customer
public class Customer
{
public string Id { get; set; } = HashId.GenerateNormalized(
Name,
BirthDate,
SocialSecurityNumber
);
public string Name { get; set; }
public DateTime BirthDate { get; set; }
public string SocialSecurityNumber { get; set; }
}
Object Checksum
public bool RecordChanged(Order order, string previousHash)
{
var currentHash = HashId.GenerateNormalized(
order.CustomerId,
order.OrderDate,
order.TotalAmount,
order.Status
);
return currentHash != previousHash;
}
Usage in LINQ
// Deduplicate records
var uniqueRecords = records
.GroupBy(r => HashId.GenerateNormalized(r.Name, r.Email))
.Select(g => g.First())
.ToList();
π Custom Normalization
using ArchSoft.HashId.Extensions;
// Individual string normalization
string normalized = " John ".NormalizeForHashing();
// Result: "john"
// Decimal number normalization
string number = 1234.50m.NormalizeForHashing();
// Result: "1234.5"
β οΈ Important Notes
- The generated hash is 64 characters long (hexadecimal representation of SHA256)
- This library generates deterministic hashes, not sequential IDs
- For cryptographic purposes, consider adding a salt
π Requirements
- .NET 8.0 or higher
π€ Contributing
Contributions are welcome! Please open an issue or pull request.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π’ About
Developed by ArchSoft - Software solutions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.