Created
April 29, 2017 20:56
-
-
Save jpdillingham/79ed10069d2e3cfc0b798068844ac217 to your computer and use it in GitHub Desktop.
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
/// <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