CSharpUtils.Hashing.GetMd5Hash C# (CSharp) Method

GetMd5Hash() public static method

public static GetMd5Hash ( Stream Stream, long>.Action ProgressAction = null ) : string
Stream Stream
ProgressAction long>.Action
return string
        public static string GetMd5Hash(Stream Stream, Action<long, long> ProgressAction = null)
        {
            if (ProgressAction == null) ProgressAction = (Current, Total) => { };

            const int MinBufferSize = 1 * 1024; // 1 KB
            const int MaxBufferSize = 1 * 1024 * 1024; // 1 MB

            byte[] Temp = new byte[Math.Max(MinBufferSize, Math.Min(MaxBufferSize, Stream.Length))];
            var md5 = MD5.Create();

            while (!Stream.Eof())
            {
                int Readed = Stream.Read(Temp, 0, Temp.Length);
                md5.TransformBlock(Temp, 0, Readed, Temp, 0);
                ProgressAction(Stream.Position, Stream.Length);
            }

            md5.TransformFinalBlock(Temp, 0, 0);
            //Md5.TransformBlock
            //return String.Join("", MD5.Create().ComputeHash(Stream).Select(Byte => Byte.ToString("x2").ToLower()));
            return BitConverter.ToString(md5.Hash).Replace("-", "").ToLower();
        }

Same methods

Hashing::GetMd5Hash ( string Path, long>.Action ProgressAction = null ) : string
Hashing