CompareMD5() public static method

Compares given MD5 hash with hash of given file
public static CompareMD5 ( string file, string hash ) : bool
file string
hash string
return bool
コード例 #1
0
ファイル: Files.cs プロジェクト: sorsarre/Razor
        /// <summary>
        /// Compares MD5 hash from given mul file with hash in responsible hash-file
        /// </summary>
        /// <param name="what"></param>
        /// <returns></returns>
        public static bool CompareHashFile(string what, string path)
        {
            string FileName = Path.Combine(path, $"UOFiddler{what}.hash");

            if (File.Exists(FileName))
            {
                try
                {
                    using (BinaryReader bin =
                               new BinaryReader(new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read)))
                    {
                        int    length = bin.ReadInt32();
                        byte[] buffer = new byte[length];
                        bin.Read(buffer, 0, length);
                        string hashold = BitConverter.ToString(buffer).Replace("-", "").ToLower();
                        return(Files.CompareMD5(Files.GetFilePath($"{what}.mul"), hashold));
                    }
                }
                catch
                {
                    return(false);
                }
            }

            return(false);
        }
コード例 #2
0
ファイル: Files.cs プロジェクト: m309/fiddler-plus
        /// <summary>
        /// Compares MD5 hash from given mul file with hash in responsible hash-file
        /// </summary>
        /// <param name="what"></param>
        /// <returns></returns>
        public static bool CompareHashFile(string what)
        {
            string path     = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string FileName = Path.Combine(path, String.Format("UOFiddler{0}.hash", what));

            if (File.Exists(FileName))
            {
                try
                {
                    using (BinaryReader bin = new BinaryReader(new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read)))
                    {
                        int    length = bin.ReadInt32();
                        byte[] buffer = new byte[length];
                        bin.Read(buffer, 0, length);
                        string hashold = BitConverter.ToString(buffer).Replace("-", "").ToLower();
                        return(Files.CompareMD5(Files.GetFilePath(String.Format("{0}.mul", what)), hashold));
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(false);
        }