C# Calculate MD5 Checksum For A File

114

C# Calculate MD5 Checksum For A File -

using System.IO;
using System.Security.Cryptography.MD5;

static string CalculateMD5(string filename)
{
    using (var md5 = MD5.Create())
    {
        using (var stream = File.OpenRead(filename))
        {
            var hash = md5.ComputeHash(stream);
            return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
        }
    }
}

Comments

Submit
0 Comments