1234567891011121314151617181920212223242526 |
- using System.Text;
- using System.Security.Cryptography;
- namespace jsonjumble.Library
- {
- public class SHA256HashGenerator
- {
- public static SHA256HashGenerator GetInstance()
- {
- return new SHA256HashGenerator();
- }
- public string Get(string text)
- {
- using (SHA256 hash = SHA256.Create())
- {
- byte[] hashValue = hash.ComputeHash(Encoding.UTF8.GetBytes(text));
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < hashValue.Length; i++)
- {
- builder.Append(hashValue[i].ToString("X2")); //Format as hexidecimal
- }
- return builder.ToString();
- }
- }
- }
- }
|