using mdfinder.hashprovider; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace mdfinder { public class MD5HashProvider : IHashProvider { /// The file extensions this hash provider works with. private readonly string[] fileExtensions = new [] { "*" }; /// The MD5 instance. private MD5 md5; /// Gets the name of the hash provider. /// The name of the hash provider. public string Name { get { return Localization.Localization.DefaultHashProviderName; } } /// Gets the description of the hash provider. /// The description. public string Description { get { return Localization.Localization.DefaultHashProviderDescription; } } /// Gets a value indicating if this hash provider is valid to use. /// /// This value can be used by hash providers to limit use of the provider. This can be used to /// create paid hash providers. /// /// The value indicating if the hash provider is valid. public bool IsValid { get { return true; } } public IEnumerable FileExtensions { get { return this.fileExtensions; } } /// /// Gets or sets the priority this provider has when multiple providers support the same /// extension. /// /// Thrown when the requested operation is not supported. /// The priority of the hash provider. public int Priority { get { return 1; } set { throw new NotSupportedException(Localization.Localization.MD5ProviderSetPriorityException); } } /// Default constructor. public MD5HashProvider() { this.md5 = MD5.Create(); } /// Gets a hash from a file. /// The file to hash. /// The hash. public string GetHash(FileInfo file) { try { return BitConverter.ToString(this.md5.ComputeHash(file.OpenRead())); } catch { // } return string.Empty; } } }