Question

I have code to generate SHA512 from string.

 public static string GetCrypt(string text)
        {
            string hash = "";
            SHA512 alg = SHA512.Create();
            byte[] result = alg.ComputeHash(Encoding.UTF8.GetBytes(text));
            hash = Encoding.UTF8.GetString(result);
            return hash;
        }
    
Now I must convert hash back to string. Any ideas how can it be done? Thank you.

Était-ce utile?

La solution

Hashes are 1-way. You can't get it back (easily). you might want actual encryption.

Autres conseils

Yes. Hashes are one-way. Please use symmetric encryption classes like RijndaelManaged.

Here is a RijndaelSimple class that I am using: http://www.obviex.com/samples/encryption.asp

The cached version of the same link is here: http://webcache.googleusercontent.com/search?q=cache:WyVau-XgIzkJ:www.obviex.com/samples/encryption.asp&hl=en&prmd=imvns&strip=1

You cant convert a hash back to string from which you computed the hash.

If you want it then you would have to compare the hash with each of the target strings hash.

If one of them matches with the hash,then that hash comes from the target string.

Its use: If you want to store passwords in database,you can store its hashes instead of passwords.So even if a hacker gets access to your database,he cant get the password cuz it is hashed.The only way to know the string through which we created the hash is to match it with the desired string!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top