15 lines
465 B
C#
15 lines
465 B
C#
|
|
using System.Security.Cryptography;
|
||
|
|
|
||
|
|
namespace EngineeringSync.Service.Services;
|
||
|
|
|
||
|
|
public static class FileHasher
|
||
|
|
{
|
||
|
|
public static async Task<string> ComputeAsync(string filePath, CancellationToken ct = default)
|
||
|
|
{
|
||
|
|
await using var stream = new FileStream(filePath,
|
||
|
|
FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true);
|
||
|
|
var hash = await SHA256.HashDataAsync(stream, ct);
|
||
|
|
return Convert.ToHexString(hash);
|
||
|
|
}
|
||
|
|
}
|