22 lines
594 B
C#
Raw Permalink Normal View History

2024-06-18 17:35:31 -04:00
using System.Security.Cryptography;
namespace ReCodeIt.Utils;
internal static class HashUtil
{
/// <summary>
/// Create a file hash from an inputed file
/// </summary>
/// <param name="filePath"></param>
/// <returns>A file hash</returns>
public static string GetFileHash(string filePath)
{
using var sha256 = SHA256.Create();
using var stream = File.OpenRead(filePath);
byte[] hashBytes = sha256.ComputeHash(stream);
var hash = BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
return hash;
}
}