Last active
December 27, 2021 14:43
-
-
Save ruyut/a712859ec0300c17401ab689321426a1 to your computer and use it in GitHub Desktop.
Get SHA256 hash
This file contains hidden or 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
| 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