Implemented the HashService and its service registration code
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user