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