Last active
July 24, 2024 11:50
-
-
Save grandsilence/e74d0fca294d0cbeda6baf581c32a306 to your computer and use it in GitHub Desktop.
C# SHA 256 to String
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
public static string Sha256(string text) | |
{ | |
var sb = new StringBuilder(); | |
using (var hash = SHA256.Create()) | |
{ | |
var result = hash.ComputeHash(Encoding.UTF8.GetBytes(text)); | |
// ReSharper disable once ForCanBeConvertedToForeach | |
for (int i = 0; i < result.Length; i++) | |
sb.Append(result[i].ToString("x2")); | |
} | |
return sb.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works great. One small glitch:
sbHash.Append => sb.Append