MD5 Hash is a great way of validating file integrity after a move. If you are uploading or downloading large files or even moving files between servers, for example: from your encoding servers to your CDN, and need a way to know the file was moved correctly consider generating an MD5 hash from the source and the destination. Comparing the two will let you know if the file was successfully moved.
public static string GetMD5HashFromFile(string fileName)
{
FileStream file = new FileStream(fileName, FileMode.Open);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
file.Dispose();
ASCIIEncoding enc = new ASCIIEncoding();
return enc.GetString(retVal);
}
Posted
17 Jul 2009 5:25 AM
by
Gal Ratner