Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrypt from SHA256

I have that code to encrypt string to sha256 and next to base64:

 public static string Sha256encrypt(string phrase)
    {
        UTF8Encoding encoder = new UTF8Encoding();
        SHA256Managed sha256hasher = new SHA256Managed();
        byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(phrase));
        return Convert.ToBase64String(hashedDataBytes);
    }

How can I decrypt my password in other side?

like image 261
netmajor Avatar asked Apr 22 '12 20:04

netmajor


1 Answers

You cannot decrypt the result of a One Way Hash. What you should do instead is compare a hash of the entered password versus the stored hash in the database.

Example:

var password = "1234";
var hashedPassword = Sha256encrypt(password);

var allowLogin = hashedPassword == storedPassword; //storedPassword from Database, etc.

This is only the very basics though, when using hashing algorithms you should consider using a Salt too.

like image 66
DaveShaw Avatar answered Sep 28 '22 11:09

DaveShaw