| 1234567891011121314151617181920212223242526272829303132 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Web;
- namespace GreenTree.Nachtragsmanagement.Web.Extensions
- {
- public static class HashHelper
- {
- /// <summary>
- /// Calculates a MD5-Hash value for a specific file
- /// </summary>
- /// <param name="filePath">Full path of the file.</param>
- public static string GetFileMd5(string filePath)
- {
- if (!File.Exists(filePath))
- throw new FileNotFoundException("The specified file does not exist.");
- using (var md5 = MD5.Create())
- {
- using (var stream = File.OpenRead(filePath))
- {
- var hash = md5.ComputeHash(stream);
- return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
- }
- }
- }
- }
- }
|