-1

I have develop a simple MD5 hash like this:

public static string Hash(string value)
{
    byte[] valueBytes = new byte[value.Length * 2];

    Encoder encoder = Encoding.Unicode.GetEncoder();
    encoder.GetBytes(value.ToCharArray(), 0, value.Length, valueBytes, 0, true);

    MD5 md5 = new MD5CryptoServiceProvider();
    byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes("123456"));

    StringBuilder stringBuilder = new StringBuilder();

    for (int i = 0; i < hashBytes.Length; i++)
    {
        stringBuilder.Append(hashBytes[i].ToString("x2"));
    }

    return stringBuilder.ToString();
}

But now, I want to decrypt the result of this code to original text. But I don't know which function I should use?

My hash function is:

byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes("123456"));
ABCD
  • 19
  • 9
  • 1
    [Cryptographic hash functions](https://en.wikipedia.org/wiki/Cryptographic_hash_function#Cryptographic_hash_algorithms) are [one-way functions](https://en.wikipedia.org/wiki/One-way_function#Cryptographically_secure_hash_functions) - which means they are not meant to be used in reverse. – Bakudan Feb 27 '19 at 16:47

1 Answers1

1

You don't (can't) decrypt a hash, you perform the encrypt again against a given value to validate that this value is the same as the one the hash pretends to belong to.

Schwarzie2478
  • 2,186
  • 26
  • 30