note 5070 deleted from function.crypt by jimw

From: Date: Sun, 16 Dec 2001 20:24:36 +0000
Subject: note 5070 deleted from function.crypt by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22935@lists.php.net to get a copy of this message
I've been reading these comments and noticed some bad things about the PHP encryption functions and some people's understanding of them. <p> First, the encrypt() and decrypt() functions talked about earlier use symmetric encryption; that is, the same key that encrypts also decrypts. So, if your key (the third argument to both functions) isn't kept completely private, you may as well have sent plaintext. <p> Second, MD5 is not really encryption. It is a cryptographic hash function. It is not used to encrypt data really. It is used to test whether a message has been altered during transit. It is "cryptographically secure" because if I send you an encrypted message with the plaintext's MD5 hash value, and a middle-man alters the encrypted message (but can't recalculate the MD5 hash value of the message, b/c it's encrypted), the MD5 hash of the plaintext that you compute will differ from mine. Then you'll know that somebody altered it. It's not used for encryption because it's a many-to-one hash function. Many, many plaintexts will map to one MD5 value. Valid encryption does not work this way. MD5 is also a one-way function, meaning that you cannot (without much difficulty) reproduce the same plaintext with its MD5 hash value. <p> You can use crypt (for passwords), md5() for a cryptographic hash function, and encrypt()/decrypt() in conjunction for some really good security on your website (but don't forget that unless you use SSL or some other encryption on the client-side that everything's being sent in plaintext). <p> What I would suggest to the creators of PHP is to write functions that use public cryptography -- algorithms like RSA -- so that we have more options. Implementing some sort of Kerberos-type authentication might work with cookies, also. <p> _Cryptography and Network Security_ by William Stallings is a good book on this stuff. <p> dn

« previous php.notes (#22935) next »