PHP

md5-based and sha1-based crypt

I had "security of information" as a subject at university and there are theorem "cryptographics hash, crypographics pseudo-random numbers generator and symetric cipher is equivalent". Few weeks after I needed symetric cipher in php, so I applied that theorem on hash function md5. After md5 was declared broken, I used same principle on hash function sha1, which exists in better version of PHP.
Usage: name.php mode password file ....
mode can be 'c' for crypt or 'd' for decrypt. Crypted file $file will be named $file.md5crypted, decrypted file $file will be named $file.plain.
Functions crypt_md5 and decrypt_md5 (resp crypt_sha1 and decrypt_sha1) is called with parameters buffer to be (de)crypted, password, time of crypting. Password and time is part of key. I put it extra to emphasize need of dynamic part of key.
sha1, current version
sha1, version 0.2
md5, current version
md5, version 0.2
Note: as reported by whateverever in php documentation of md5, if you use crypt_md5 (or crypt_sha1) on its own output with same time and key, first 16 (or 20) bytes of buffer will end non-encrypted. That is not bug: time is simply expected to not be same. If you need to crypt more buffers per second, it will be safer to use for example microtime() (float version) instead of time().
Homepage root


Free web hostingWeb hosting