Files
components/LiteCharms.Features/Utilities/Commands/Handlers/ComputeHashCommandHandler.cs
T
2026-05-03 16:10:27 +02:00

19 lines
560 B
C#

namespace LiteCharms.Features.Utilities.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));
}
}
}