implement Phase 1-2
This commit is contained in:
parent
41573b3c4f
commit
b976cf3124
23 changed files with 1291 additions and 79 deletions
20
backend/WordVersioning.Api/Services/HashService.cs
Normal file
20
backend/WordVersioning.Api/Services/HashService.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue