Generate MD5 hashcodes to check the Integrity of a file on a client

Use MD5 hashcodes generated on the server, to see and check if the files have been modified on the client, therby you can estalish the Integrity of the file.

public static string GenerateMD5(string FileName)
        {
            MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider();
            FileStream fs = null;
            byte[] hash = null;

            try
            {
                fs = File.OpenRead(FileName);
                hash = csp.ComputeHash(fs);
            }
            finally
            {
                if(fs != null)
                    fs.Close();
            }

            if(hash != null)
                return BitConverter.ToString(hash).Replace("-", "").ToLower();
            else
                return string.Empty;
        }
By [)ia6l0 iii   Popularity  (922 Views)