Skip to content

Instantly share code, notes, and snippets.

@lawrencekgrant
Created July 29, 2011 01:40
Show Gist options
  • Save lawrencekgrant/1112964 to your computer and use it in GitHub Desktop.
Save lawrencekgrant/1112964 to your computer and use it in GitHub Desktop.
Simply hash a file in C#
using System.IO;
using System.Security.Cryptography;
//Example: Hash("myfile.txt", "SHA-512");
public string Hash(string inputFile, string algorithm)
{
HashAlgorithm hash = HashAlgorithm.Create (algorithm);
FileStream fileStream = File.OpenRead (inputFile);
byte[] hashBytes = hash.ComputeHash (fileStream);
return Convert.ToBase64String (hashBytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment