-8

Hello i'm trying to make a simple encrypt,decrypt algorithm and i maked encrypt code correctly,but description code not working

    static string Encript(string value)
    {
        using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
        {
            UTF8Encoding utf8 = new UTF8Encoding();
            byte[] data = md5.ComputeHash(utf8.GetBytes(value));
            return Convert.ToBase64String(data);
        }
    }

    static string Decript(string value)
    {
        using (TripleDESCryptoServiceProvider Tdecript = new TripleDESCryptoServiceProvider())
        {

             UTF8Encoding utf8 = new UTF8Encoding();
             byte[] DataToDecrypt = Convert.FromBase64String(value);
             return utf8.GetString(DataToDecrypt);
        }
    }

this is show when i press decript button

2 Answers2

2

First of all you are using a Hash Function to "encrypt" your data. Hashing is a one way function. Thus you will not be able to "decrypt" your data.

Second of all: MD5 is not a good hashing mechanism. Please use something like SHA256.

Third: To encrypt + decrypt I would recommend you to use AES256.

Here is a sample on how to achieve this:

AESManaged Microsoft

dominik
  • 1,319
  • 13
  • 23
-1

This may not answer you original question but do not use MD5 - it is considered broken. I would use sha-256 as a minimum if you actually want to keep the information you are hashing secure.

To answer you question

To my knowledge the MD5 hash you are using is a one way function - meaning you take a password and hash it, stick it in a db - when a user comes back you do not decrypt the data and check the two values match but you create a new hash of the data they gave you and compare these two.

If you need a two way encryption service I would look at AES.

monkeylumps
  • 747
  • 4
  • 10
  • 23