Exemple #1
0
    public static string GetMD5(string fileName)
    {
        FileStream fileStream = (FileStream)null;
        MD5CryptoServiceProvider cryptoServiceProvider = (MD5CryptoServiceProvider)null;

        try
        {
            if (!System.IO.File.Exists(fileName))
            {
                throw new FileNotFoundException("File not found", fileName);
            }
            fileStream            = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            cryptoServiceProvider = new MD5CryptoServiceProvider();
            cryptoServiceProvider.ComputeHash((Stream)fileStream);
            return(CUtils.BytesToStr(cryptoServiceProvider.Hash));
        }
        finally
        {
            if (fileStream != null)
            {
                fileStream.Close();
            }
            if (cryptoServiceProvider != null)
            {
                cryptoServiceProvider.Clear();
            }
        }
    }