Implemented the HashService and its service registration code

This commit is contained in:
Khwezi Mngoma
2026-05-31 19:37:19 +02:00
parent f88cc42a88
commit 48f4cd45f1
16 changed files with 163 additions and 23 deletions
+18 -8
View File
@@ -1,13 +1,23 @@
namespace LiteCharms.Features.Extensions;
using LiteCharms.Features.Hasher;
using LiteCharms.Features.Hasher.Configuration;
namespace LiteCharms.Features.Extensions;
public static class Hash
{
public static readonly Func<string?, string?> StringToSha256Hash = (input) =>
Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(input!)));
public const string HasherConfigSectionName = "HasherSettings";
public static readonly Func<Stream, string?> StreamToSha256Hash = (stream) =>
Convert.ToHexString(SHA256.HashData(stream));
public static IServiceCollection AddHashServices(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<HasherSettings>(configuration.GetSection(HasherConfigSectionName));
public static readonly Func<byte[], string?> BytesToSha256Hash = (bytes) =>
Convert.ToHexString(SHA256.HashData(bytes));
}
var settings = configuration.GetSection(HasherConfigSectionName).Get<HasherSettings>();
services.AddSingleton<IHashids>(_ =>
new Hashids(settings!.Salt, minHashLength: settings.MinHashLength));
services.AddSingleton<HashService>();
return services;
}
}