software-mariodiana
3/21/2016 - 8:49 PM

Write out a digest file.

Write out a digest file.

/*
 * System.IO
 * System.Security.Cryptography
 */

string path = GetPathToFileYouWantToHash();

byte[] data = File.ReadAllBytes(path);

SHA512Managed sha = new SHA512Managed();
byte[] digest = sha.ComputeHash(data);

// http://stackoverflow.com/a/623134/155167
string hex = String.Concat(digest.Select(b => b.ToString("x2")));

string digestFilePath = GetPathForDigestFile();

File.WriteAllText(digestFilePath, hex, Encoding.ASCII);