Get File MD5 - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:MD5

Description

Get File MD5

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.IO;//from  ww  w. j  a va 2  s .  c  o m
using System;

public class Main{
        public static string GetFileMD5(string fileName)
        {
            FileStream stream = new FileStream(fileName, FileMode.Open);
            int length = (int) stream.Length;
            byte[] buffer = new byte[length];
            stream.Read(buffer, 0, length);
            stream.Close();
            byte[] buffer2 = new MD5CryptoServiceProvider().ComputeHash(buffer);
            string str = " ";
            foreach (byte num2 in buffer2)
            {
                string str2 = "0" + Convert.ToString(num2, 0x10);
                str2 = str2.Substring(str2.Length - 2);
                str = str + str2;
            }
            return str;
        }
}

Related Tutorials