I have a class where it is responsible for generating a hash according to what I send to it. However, the return of the SHA256Managed.Create(text)
method is always returning null
.
The following is my code:
using System.Security.Cryptography;
using System.Text;
namespace Autenticacao_no_ASP_.NET_MVC.Utils
{
public class Hash
{
public static string GerarHash(string texto)
{
SHA256 sha256 = SHA256Managed.Create(texto);
byte[] bytes = Encoding.UTF8.GetBytes(texto);
byte[] hash = sha256.ComputeHash(bytes);
StringBuilder result = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
result.Append(hash[i].ToString("X"));
}
return result.ToString();
}
}
}
sha256 which is being returned null.