0

I want to encrypt a string value with md5 and then decrypt it so I so that it possible with a key. So I searched how to do this and I found only one other alghorithm.

This is the encryption class:

class crypt
    {

        public string encrypt(string bhash)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(bhash));
            byte[] result = md5.Hash;
            StringBuilder strBuilder = new StringBuilder();
            for (int i = 0; i < result.Length; i++)
            {
                strBuilder.Append(result[i].ToString("x2"));
            }
            bhash = strBuilder.ToString();
            return bhash;
        }
    }
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Tomer Peretz
  • 11
  • 1
  • 1
  • 3
    What you are doing is hashing. Hashing is irreversible. You can only compare hashes – Taylor Swift Jul 31 '15 at 22:37
  • MD5 is a one way hash. You can encrypt but can't really decrypt. PS: You don't need stringbuilder there. You could use BitConverter or you could use base64 encoding to get a text version to save as a string. – Cetin Basoz Jul 31 '15 at 22:41
  • To add something md5 is not recommended anynore – Juan Jul 31 '15 at 23:22

1 Answers1

1

The only way to decrypt an md5 encryption is through brute forcing all the possible original content.

There is no algorithm for decryption. You must test out all possible values and encrypt them and check for a match to find the original value.

Krikor Ailanjian
  • 1,842
  • 12
  • 17
  • yea but if i encrypt with a key i cant? like here:https://social.msdn.microsoft.com/Forums/vstudio/en-US/d6a2836a-d587-4068-8630-94f4fb2a2aeb/encrypt-and-decrypt-a-string-in-c the RSA Alogorithm. – Tomer Peretz Jul 31 '15 at 22:59
  • 1
    RSA is an asymmetric encryption algorithm using public and private keys, one key used to encrypt, the other to decrypt. MD5 is a hash function, not intended for easy decryption. More info on this post: http://security.stackexchange.com/questions/2298/what-are-the-differences-between-md5-sha-and-rsa – redspidermkv Jul 31 '15 at 23:10
  • md5 is designed to yield consistent results when encoded but results that cannot be decoded. A popular use is in systems where there is a database of encrypted passwords. The user can enter a password, the password is encrypted and checked against the database value. It is similarly used in software validation. – Krikor Ailanjian Aug 01 '15 at 02:03