Files
components/LiteCharms.Features/Utilities/Hash/Commands/Handlers/ComputeHashCommandHandler.cs
T

21 lines
617 B
C#

using LiteCharms.Features.Utilities.Hash.Commands;
namespace LiteCharms.Features.Utilities.Hash.Commands.Handlers;
public class ComputeHashCommandHandler : IRequestHandler<ComputeHashCommand, Result<string>>
{
public async ValueTask<Result<string>> Handle(ComputeHashCommand request, CancellationToken cancellationToken)
{
try
{
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(request.Input!));
return Result.Ok(Convert.ToHexString(bytes));
}
catch (Exception ex)
{
return Result.Fail<string>(new Error(ex.Message).CausedBy(ex));
}
}
}