Whenever I use the SHA256.Create() method it always returns a null value. Here is the method I have for encrypting a password …
private string EncryptPassword(string password)
{
SHA256 sha = SHA256.Create(password);
return BitConverter.ToString(sha.Hash);
}
The debugger shows that the variable sha is null. I have even tried putting it in its own method in a controller but I still get a System.NullReferenceException
public String Index()
{
return BitConverter.ToString(SHA256.Create("Hello World").Hash);
}
I am completely lost. Is there something that I am obviously doing wrong?
Yes,
Create()isn’t meant for the message, it specifies the SHA256 implementation.I suspect you want to use the implementation class
SHA256Managedinstead.http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha256managed.aspx
Example: