Get MD5 Hash for a Stream - CSharp Security

CSharp examples for Security:MD5

Description

Get MD5 Hash for a Stream

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.IO;//from  ww w . ja v  a 2s  . c om
using System;

public class Main{
        public static string GetMD5Hash(MD5 md5, Stream stream)
        {
            byte[] data = md5.ComputeHash(stream);
            StringBuilder sBuilder = new StringBuilder();

            // Loop through each byte of the hashed data 
            // and format each one as a hexadecimal string.
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }

            // Return the hexadecimal string.
            return sBuilder.ToString();
        }
}

Related Tutorials