note 3492 deleted from crypt by ronabop

From: Date: Sat, 09 Sep 2000 02:42:25 +0000
Subject: note 3492 deleted from crypt by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-4579@lists.php.net to get a copy of this message
As I see it, the crypt() function doesn't support decryption (This is simply a security matter, so that you have to have the exact same string that once was crypted, then crypt it using crypt(), and compare the old crypted string with the new one.)<BR> It's also right that you then don't have the ability to (for example) send a user his or hers password to their e-mail address - because you don't know it your self... you only have the crypted version of the password.<BR> I looked at the online PHP manual and didn’t find the two functions encrypt() and decrypt(). Therefore I've taken the liberty to quote the great book "Core PHP Programming" by Leon Atkinson, where to two functions are discussed: <P> First the decrypt() function:<BR> string decrypt(string data, integer method, string key)<BR> The decrypt() function attempts to transform an encrypted string passed as the data argument into plain text using the method specified by the method argument and the key from the key argument. Each of the four methods uses a single key that both encrypts and decrypts. The methods are listed below: <P> METHOD: NAME: MINIMUM DATA LENGTH: REQUIRED KEY SIZE:<br> 0 IDEA 8 characters 16 characters <br> 1 MDC 8 characters 8 characters <br> 2 DES 32 characters 16 characters <br> 3 XOR 16 characters 16 characters <br> <P> Then the encrypt() function:<BR> string encrypt(string data, integer method, string key)<BR> To encrypt the data you wish to later decrypt, use the encrypt() function. Data are encrypted using one of four methods and a key. See the description of the decrypt() function for more information. <P> Example: <P> $message = "this is a plain text message";<br> $password = "secret";<br> $data = encrypt($message, 0, $password);<br> print(decrypt($data, 0, $password));<br> <p> Once again (I've been getting some e-mails on this subject): the crypt() function is a one-way-algorithm - There is no way to decrypt the information crypted with crypt(). If you want to crypt something that shall later be decrypted, you can use the encrypt() and decrypt() function (as I've discussed above, but the two functions are not enabled by default in PHP3 - See further down on how to do this). <p> While working with PHP and crypting I've also discovered another function: "md5()". This function does the same as crypt(), but while crypt() doesn't work on a windows platform (as far as I know) the md5() does. The md5() is by far more secure than crypt() as crypt() only looks at the 1st 8 chars. <p> To find out how the two functions encrypt() and decrypt() works, I contacted Leon Atkinson, author of "Core PHP Programming". Here is what he wrote: <br> -------------------------------- <br> There's two problems. First, you need to enable the php3_crypt.dll to make the functions available. You can do that either by uncommenting the line: <p> extension=php3_crypt.dll <p> in your php3.ini file, or you can use dl(), such as: <p> dl("extension=php3_crypt.dll"); <p> prior to calling the functions. The second problem is that these functions have seem to be abandoned in PHP4 in favor of a new module called mcrypt. But the mcrypt functions aren't available for PHP3. If you want to play around with these functions, you may need to change my example. It didn't run for me in 3.0.12 until I changed the password to be 16 characters long. <br> Good Luck,<br> Leon <br> <br> -------------------------------- <br> - Watson

« previous php.notes (#4579) next »