How to decrypt md5 password in c#.net?

QuestionsCategory: C#How to decrypt md5 password in c#.net?
AnynoumusAnynoumus asked 4 years ago

How to decrypt md5 password in c#.net?

1 Answers
Best Answer
Mahesh DeshmaneMahesh Deshmane answered 4 years ago

 

MD5 is one way hash function and in general hash algorthims are irreversible that means once we hashed there is no way to get the original value from the hash.

For more information you can read the post MD5

Here is code snippet which is used MD5 hash for creating key with Triple DES for encryption and decryption.


public static string Encrypt(string text, string key)
{
    var data = Encoding.UTF8.GetBytes(text);
                
    using (var md5 = new MD5CryptoServiceProvider())
    {
        var keys = md5.ComputeHash(Encoding.UTF8.GetBytes(key));
        using (var tripDes = new TripleDESCryptoServiceProvider { Key = keys, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 })
        {
            var transform = tripDes.CreateEncryptor();
            var results = transform.TransformFinalBlock(data, 0, data.Length);
            return Convert.ToBase64String(results, 0, results.Length);
        }
    }
}
    
public static string Decrypt(string cipher, string key)
{
    var data = Convert.FromBase64String(cipher);
    using (var md5 = new MD5CryptoServiceProvider())
    {
        var keys = md5.ComputeHash(Encoding.UTF8.GetBytes(key));
                            
        using (var tripDes = new TripleDESCryptoServiceProvider()
        {
            Key = keys, Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 })
            {
                var transform = tripDes.CreateDecryptor();
                var results = transform.TransformFinalBlock(data, 0, data.Length);
                return Encoding.UTF8.GetString(results);
            }
        }
    }
}