using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace Fort23.Core
{
    public static class MD5Helper
    {
        public static string FileMD5(string filePath)
        {
            // if (!filePath.Contains(".manifest"))
            // {
            //     return "";
            // }

            byte[] retVal;
            using (FileStream file = new FileStream(filePath, FileMode.Open))
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                retVal = md5.ComputeHash(file);
            }

            return ByteArrayToString(retVal);
        }
        public static string FileMD5(byte[] data)
        {
            byte[] retVal;
            MD5 md5 = new MD5CryptoServiceProvider();
            retVal = md5.ComputeHash(data);

            return ByteArrayToString(retVal);
        }
        public static string ByteArrayToString(byte[] ba)
        {
            StringBuilder hex = new StringBuilder(ba.Length * 2);
            foreach (byte b in ba)
            {
                hex.AppendFormat("{0:x2}", b);
            }

            return hex.ToString();
        }
    }
}