From b498ec86168bf9ac50d9272581a9b87605476499 Mon Sep 17 00:00:00 2001 From: Mathias Beaulieu-Duncan Date: Wed, 8 Oct 2025 11:38:29 -0400 Subject: [PATCH] added GetHash helper --- .../ServiceCollectionExtensions.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Svrnty.GeoManagement.Abstractions/ServiceCollectionExtensions.cs b/Svrnty.GeoManagement.Abstractions/ServiceCollectionExtensions.cs index e5c5dbb..44ae291 100644 --- a/Svrnty.GeoManagement.Abstractions/ServiceCollectionExtensions.cs +++ b/Svrnty.GeoManagement.Abstractions/ServiceCollectionExtensions.cs @@ -1,3 +1,5 @@ +using System.Security.Cryptography; +using System.Text; using Svrnty.GeoManagement.Abstractions.Abstractions; using Svrnty.GeoManagement.Abstractions.Models; @@ -65,4 +67,16 @@ public static class ServiceCollectionExtensions return $"{address.Line2}, {address.Line1}\n{address.City}, {address.Subdivision} {address.PostalCode}\n{address.CountryCode}"; } + + public static string GetHash(this IAddress address) + => ComputeSha256Hex(address.GetFormattedAddress()); + + private static string ComputeSha256Hex(string input) + { + using SHA256 sha256 = SHA256.Create(); + byte[] bytes = Encoding.UTF8.GetBytes(input); + byte[] hash = sha256.ComputeHash(bytes); + + return Convert.ToHexString(hash).ToLower(); + } } \ No newline at end of file