Skip to content

Instantly share code, notes, and snippets.

@ruyut
Last active December 27, 2021 14:43
Embed
What would you like to do?
Get SHA256 hash
namespace Ruyut.Helpers
{
public static class Sha256Helper
{
/// <summary>
/// Get SHA256 hash
/// </summary>
/// <param name="str"></param>
/// <example>
/// For example:
/// <code>
/// Sha256("Ruyut");
/// </code>
/// results in <c>e5a47100b733b86f6fc82b9b614c4829bc9042ca3f24a65c5c2783c699ed6625</c>
/// </example>
public static string Sha256(string str)
{
byte[] sha256Bytes = Encoding.UTF8.GetBytes(str);
SHA256Managed sha256 = new SHA256Managed();
byte[] bytes = sha256.ComputeHash(sha256Bytes);
return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment