Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have setup my password as hash and stored into the database as a varchar
But i want to retrieve and convert it back to text as it was
How do i do it

Heres how i converted it to hash:

What I have tried:

protected string MD5Hash(string input)
{
    StringBuilder stringBuilder = new StringBuilder();
    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    byte[] bytes = md5.ComputeHash(new UTF8Encoding().GetBytes(input));
    for (int i = 0; i < bytes.Length; i++)
    {
        stringBuilder.Append(bytes[i].ToString("x2"));
    }
    return stringBuilder.ToString();

}
Posted
Updated 26-Nov-22 17:15pm

A hash by definition cannot be converted back to the original.

What you can do is hash a new string and compare the two hashes. If they match then the new string is what the old one was before it was hashed.
 
Share this answer
 
Quote:
I have setup my password as hash and stored into the database as a varchar
But i want to retrieve and convert it back to text as it was
How do i do it

Short answer: you can't !
MD5 hash is a one way process, like any other hash. you can't reverse it, it is by design.
Contrary to encryption which can be decrypted.
 
Share this answer
 
Comments
Subit Timalsina 7-May-18 9:30am    
so whats the best way to store password securely and that is reversible too?
Patrice T 7-May-18 9:37am    
Reversible imply encryption !
You can't get the original data from a hash. That is by design. If you need to decrypt, you have to use an encryption method instead of a hash.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900