How can I decrypt an MD5 hash to a string using PHP?
-
2Hash functions are one way functions: http://en.wikipedia.org/wiki/Hash_functions – Felix Kling Mar 21 '11 at 23:37
-
www.freerainbowtables.com tries to reverse engineer simple passwords, but the idea is that MD5 should remain a mystery. – Patrick Beardmore Mar 21 '11 at 23:58
4 Answers
Hashing isn't encryption - you can't.

- 88,732
- 13
- 198
- 189
-
1
-
In some how he can crack it by generating hash's and compare it against what he want like world list. – SIFE Mar 22 '11 at 00:02
-
2No he can't. He can potentially find data that produces the same hash. He cannot reliably regenerate the original string. – Erik Mar 22 '11 at 00:11
There is no way to decrypt a hash. Hash functions are, by nature, 1 way functions.
if you're trying to create encryption for users data then you should be using normal encrypt/decrypt functions.
If you're trying to decrypt 'hashed' passwords, well.... good luck with that one.

- 636
- 5
- 16
You should read up on what it actually does before you assume its decryptable, im not going to go into much detail but MD5 is infact floored and should not be used at all.
MD5 hashes can collide meaning to totally different strings can produce the same hash, causing a exploit in the algorithm.
if you want a 2 way encryption you should do something like so:
$key = 'password to (en/de)crypt';
$string = 'string to be encrypted';
//Encrypt
base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256,md5($key),$string,MCRYPT_MODE_CBC,md5(md5($key))));
//Decrypt
rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
As quoted from: Best way to use PHP to encrypt and decrypt passwords?

- 1
- 1

- 56,863
- 21
- 114
- 161
If you're looking for decryption, you can create (or get) rainbow tables - essentially, create a password generator that encrypts with MD5 and invent as many hashes as you want. Save the hashes to a database. From there, do a search for your hash.

- 470
- 1
- 12
- 34