/// <summary>
/// Display the hash codes of random created file
/// </summary>
public static void Hash()
{
// 1. Create a random file
FileInfo fileToHash = RandomFile.CreateRandomBinary();
if (fileToHash == null)
{
throw new Exception("Can't create test file");
}
Console.WriteLine("Created random file: {0}", fileToHash.FullName);
// 2. Print the MD5 hash code
IHash hashObject = new Hash();
hashObject.SetAlgorithm(AvailableHash.MD5);
Console.WriteLine("MD5 hash: {0}", hashObject.ComputeHashFileStyle(fileToHash.FullName, HexStyle.UNIX));
// 3. Print the SHA1 hash code
hashObject.SetAlgorithm(AvailableHash.SHA1);
Console.WriteLine("SHA1 hash: {0}", hashObject.ComputeHashFileStyle(fileToHash.FullName, HexStyle.UNIX));
// 4. Print the TIGER hash code
hashObject.SetAlgorithm(AvailableHash.TIGER);
Console.WriteLine("TIGER hash: {0}", hashObject.ComputeHashFileStyle(fileToHash.FullName, HexStyle.UNIX));
// 5. Delete file
fileToHash.Delete();
Console.WriteLine("Deleted random file: {0}", fileToHash.FullName);
}