Exemple #1
0
        /// <summary>
        /// A method for getting a TTH hash from a specified file path
        /// </summary>
        /// <param name="filePath">The path for the file to hash</param>
        /// <returns>A string containing the TTH hash</returns>
        public static string GetTTH(string filePath)
        {
            TTH_Optimized TTH  = new TTH_Optimized();
            string        hash = HashStringConverter.ToBase32String(TTH.GetTTH(filePath)).ToLower();

            return(hash);
        }
Exemple #2
0
        /// <summary>
        /// A method for getting a MD5 hash from a specified file path
        /// </summary>
        /// <param name="file">The FileStream to hash</param>
        /// <returns>A string containing the MD5 hash</returns>
        public static string GetMD5(FileStream file)
        {
            string hash = String.Empty;

            using (HashAlgorithm hasher = MD5.Create())
            {
                byte[] buffer;
                int    bytesToRead    = 0;
                long   totalBytesRead = 0;

                do
                {
                    buffer = new byte[4096];

                    bytesToRead = file.Read(buffer, 0, buffer.Length);

                    totalBytesRead += bytesToRead;

                    hasher.TransformBlock(buffer, 0, bytesToRead, null, 0);
                }while (bytesToRead != 0);

                hasher.TransformFinalBlock(buffer, 0, 0);

                hash = HashStringConverter.MD5HashStringBuilder(hasher.Hash);
            }

            return(hash);
        }
Exemple #3
0
        /// <summary>
        /// A method for getting a TTH hash from a specified file path
        /// </summary>
        /// <param name="file">The FileStream to hash</param>
        /// <returns>A string containing the TTH hash</returns>
        public static string GetTTH(FileStream file)
        {
            TTH_Optimized TTH  = new TTH_Optimized();
            string        hash = HashStringConverter.ToBase32String(TTH.GetTTH(file.Name)).ToLower();

            return(hash);
        }