Shawazi, as has been pointed out there isn't any particular MD5 decryption function, however, the MD5 hashes can be broken (not quickly or easily but it can be done). I don't recommend using it for passwords and other important or sensitive information. I would use the libmcrypt extension instead. Use long keys and make sure you store the key off the web or public directory at your site (or recommend that if it's open source). If you can't install the libmcrypt extension (or for open source not everyone will have mcrypt available), then you can use a home grown type of encryption and decryption routines. Here is an example of one:
http://www.phpbuilder.com/snippet/detail.php?type=snippet&id=1290. It may not be the most secure but it's adequate, considering you can change the key and it uses an IV number. Here's some sample output from it:
SAMPLE 1:
Original text: Hello World!
IV number generated: 311
Encoded text: URAyxFbAtJwqe9oq0P
Text after decode: Hello World!
SAMPLE 2:
Original text: Hello World!
IV number generated: 76
Encoded text: UMXyM4bMcJcse6Rqc5
Text after decode: Hello World!
I think it's generally best to use mcrypt whenever possible and pick one of the many ciphers available. I recently became aware of a PEAR script that can do a blowfish cipher without mcrypt. It can be found at: http://pear.php.net/package/Crypt_Blowfish
I downloaded it to give it a quick try. It works and produces the same encrypted value as the one used by mcrypt (important thing to test). The heart of this script is a class inside Blowfish.php.
It actually looks to see if mcrypt is installed, and guess what? Yes, you guessed it! It uses mcrypt if it's installed. It does work without it installed too, but if mcrypt is installed it uses that instead of it's own code.
I decided to quickly try some elementary speed tests on encrypting and decrypting with this new Blowfish.php class. I tested the class with and without mcrypt installed to see the difference in speed if any. I used a simple key: 'A very secret key' and a small amount of text to encrypt: 'This is a test'
I used my Windows XP Pro 3Ghz machine with PHP 5.0.4 under Apache 2, and the results are below.
Average times using Blowfish.php class without mcrypt installed:
Seconds to encrypt: 0.047564029693604
Seconds to decrypt: 0.00019288063049316
Average times using Blowfish.php class with mcrypt installed:
Seconds to encrypt: 0.00062704086303711
Seconds to decrypt: 5.0783157348633E-005
It was interesting to see that with mcrypt installed the decryption time went considerably up (slower) while the encryption time was faster.
So, of course I had to test the mcrypt by itself. Below are the results.
Average times using just mcrypt (not the new Blowfish.php class):
Seconds to encrypt: 0.00064682960510254
Seconds to decrypt: 0.0006110668182373
It is clear to me that using mcrypt has an overall significant speed performance gain than using the Blowfish.php class (with or without mcrypt installed).
If one doesn't have mcrypt installed, then of course this is a pretty good class to use (but still needs the PEAR package to be installed).
I was debating whether to provide the following information/links or not. I decided to present it to educate people about the use of MD5 and since the information are already readily available on the Internet.
You can download a Windows program that cracks MD5 hashes (although I've only seen it crash more than work):
http://members.cox.net/geno023/MD5Cracker.zip
Here's a PHP command prompt script that is supposed to crack MD5 hashes and keys:
http://www.securiteam.com/tools/5XP0X0040G.html
You can even submit an MD5 to be cracked online for free (they've had success with 8 characters and less):
http://www.passcracking.com
Password guessing:
http://packages.debian.org/testing/admin/crack-md5
A 2004 Article on the MD5 (and SH-0, SH-1) vulnerability:
http://www.technewsworld.com/story/35926.html
Cracking MySQL's MD5() function with the rainbow project (see below this):
http://alan.blog-city.com/cracking_mysqls_md5_function__within_seconds.htm
Project RainbowCrack:
http://www.antsight.com/zsl/rainbowcrack/
It doesn't use the brute force method but it can't handle salts either. RainbowCrack creates a table precomputation which is to precompute and store encryptions of a chosen plain text and corresponding keys for all possible keys. This takes a long time to create the tables. But once created some MD5 hashes can be broken in seconds. There's a configuration they have for lowercase alphanumeric values between 1 and 8 characters long that would literally take weeks (or months) for it to compute the tables on my computer. And you would need 36 GB of space. If you did it though, then you could crack at a 99% success rate. But remember, that's only for up to 8 characters (lowercase alphanumeric).
Let's say I wanted to crack all the letters and symbols of the alphabet (including spaces) and the original plain text could be between 1-20 characters long. Well, that would require a lot of disk space and time if I was running it just on my computer. It will take about 587898660426650803072995226 years to compute such a table. LOL, I better get started then!
I hope all this helps.
🙂