Search code examples
c#asp.netsecuritysalt-cryptographyhashalgorithm

get string value of password from hash value


I have created a hash value for password using the below code.. I am storing the value which is returned from the below method.

public static string CreateHash(string password)
{
    // Generate a random salt
    RNGCryptoServiceProvider csprng = new RNGCryptoServiceProvider();
    byte[] salt = new byte[24];
    csprng.GetBytes(salt);
    HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();
    byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(salt + ":" + password);
    // Hash the password and encode the parameters
    byte[] bytHash = hashAlg.ComputeHash(bytValue);
    return
        Convert.ToBase64String(bytHash);
}

Now i want to decode the value of the above created hash.. I need the string value of the password.. How do i do that..?


Solution

  • SHA-256 is a one-way hash algorithm. You can't get the original text back from the hash, short of brute-force guessing.