19 lines
560 B
C#
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));
|
|
}
|
|
}
|
|
}
|