Created
July 29, 2011 01:40
-
-
Save lawrencekgrant/1112964 to your computer and use it in GitHub Desktop.
Simply hash a file in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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