Skip to content

Instantly share code, notes, and snippets.

@jpdillingham
Created April 29, 2017 20:56
Show Gist options
  • Save jpdillingham/79ed10069d2e3cfc0b798068844ac217 to your computer and use it in GitHub Desktop.
Save jpdillingham/79ed10069d2e3cfc0b798068844ac217 to your computer and use it in GitHub Desktop.
/// <summary>
/// Computes and returns the SHA512 hash of the specified string.
/// </summary>
/// <param name="content">The string for which the SHA512 hash is to be computed.</param>
/// <returns>The SHA512 hash of the specified string.</returns>
public static string ComputeSHA512Hash(string content)
{
return ComputeSHA512Hash(Encoding.ASCII.GetBytes(content));
}
/// <summary>
/// Computes and returns the SHA512 hash of the specified byte array.
/// </summary>
/// <param name="content">The byte array for which the SHA512 hash is to be computed.</param>
/// <returns>The SHA512 hash of the specified byte array.</returns>
public static string ComputeSHA512Hash(byte[] content)
{
byte[] hash;
using (SHA512 sha512 = new SHA512Managed())
{
hash = sha512.ComputeHash(content);
}
StringBuilder stringBuilder = new StringBuilder(128);
foreach (byte b in hash)
{
stringBuilder.Append(b.ToString("X2"));
}
return stringBuilder.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment