Search code examples
phpalgorithmencryptioncrypt

PHP crypt function and algorithm


I'm using crypt() function but I don't know if my implementation is correct. What kind of algorithm I'm using if I write someting like this :

crypt('PE','12345') 

I read the documentation and I don't know which algorithm is chosen with a five char salt like 12345.


Solution

  • Depends on the system as the documentation says.

    To determine what your system supports, you can check the values of constants defined by PHP. The constant CRYPT_SALT_LENGTH will display the expected length of the salt string. DES accepts a two-character salt. MD5 accepts 12 characters. You can also check to see whether any of the following flags are set: CRYPT_STD_DES, CRYPT_EXT_DES, CRYPT_MD5, CRYPT_BLOWFISH. To do this, issue a command such as: echo CRYPT_MD5

    A numeral 1 indicates it is supported; a 0 indicates that it is not.

    Consider reading details here http://www.techrepublic.com/article/the-perils-of-using-php-crypt/1058691