简体   繁体   中英

Get the plain text back from hash code in C#

I have some simple code but I need to get back my plain text from my hash code.

    private string Hash(string ToHash)
    {
        // First we need to convert the string into bytes,
        // which means using a text encoder.
        Encoder enc = System.Text.Encoding.ASCII.GetEncoder();

        // Create a buffer large enough to hold the string
        byte[] data = new byte[ToHash.Length];
        enc.GetBytes(ToHash.ToCharArray(), 0, ToHash.Length, data, 0, true);

        // This is one implementation of the abstract class MD5.
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] result = md5.ComputeHash(data);
        return BitConverter.ToString(result);
    }

As far as I am aware, you can't un-hash something. It simply goes against the idea of hashing. Are you sure you are not thinking about 'encrypting'? As with a symmetric or asymmetric key?

You should not be able to reverse a hash - it is by definition a one-way function. You might be able to guess what the plaintext of an md5 hash is by using a rainbow table or brute force guessing but it is expensive and not really what you're looking for.

Are you trying to compare a password someone entered to the stored hash of their password? If so, then instead of trying to unhash the stored password, you just need to hash the password they enter and then compare the two hashes to see if they match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM