eCourt-Doc-Edit/backend/WordVersioning.Api/Services/HashService.cs
Suphonchai Phoonsawat b976cf3124 implement Phase 1-2
2026-08-19 10:54:55 +07:00

20 lines
772 B
C#

using System.Security.Cryptography;
namespace WordVersioning.Api.Services;
public interface IHashService
{
/// <summary>คำนวณ SHA256 ระหว่าง stream ผ่าน — คืน hex ตัวเล็ก
/// (อ่านจนจบ stream — caller ต้อง Seek(0) เองถ้าจะใช้ stream ต่อ)</summary>
Task<string> ComputeSha256HexAsync(Stream stream, CancellationToken ct = default);
}
public class HashService : IHashService
{
public async Task<string> ComputeSha256HexAsync(Stream stream, CancellationToken ct = default)
{
using var sha = SHA256.Create();
var hash = await sha.ComputeHashAsync(stream, ct);
return Convert.ToHexString(hash).ToLowerInvariant();
}
}