2

How can I decrypt an MD5 hash to a string using PHP?

GrumpyCrouton
  • 8,486
  • 7
  • 32
  • 71
master
  • 31
  • 1
  • 1
  • 2

4 Answers4

4

Hashing isn't encryption - you can't.

Erik
  • 88,732
  • 13
  • 198
  • 189
3

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.

dbers
  • 636
  • 5
  • 16
2

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?

Community
  • 1
  • 1
RobertPitt
  • 56,863
  • 21
  • 114
  • 161
0

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.

thebarless
  • 470
  • 1
  • 12
  • 34