PHP crypt Function
What is crypt Function and how it is used in string?
In PHP, this function is used for one-way string encryption or hashing.
And also it uses different algorithms like DES,MD5, BLOWFISH, based on the values of constants used along with the crypt function.
|CONSTANT ||DESCRIPTION |
|CRYPT_STD_DES ||Standard DES-based encryption with a two character salt |
|CRYPT_EXT_DES ||Extended DES-based encryption with a nine character salt |
|CRYPT_MD5 ||MD5 encryption with a twelve character salt starting with $1$ |
|CRYPT_BLOWFISH ||Blowfish encryption with a sixteen character salt starting with $2$ or $2a$ |
In the above syntax "str" specifies the string to be encrypted,"salt" is the number of characters to be encoded.
if (CRYPT_STD_DES == 1)
echo "Standard DES: ".crypt("hiox india")."n<br/>";
if (CRYPT_EXT_DES == 1)
echo "Extended DES: ".crypt("hiox india")."n<br/>";
if (CRYPT_MD5 == 1)
echo "MD5: ".crypt("hiox india")."n<br/>";
if (CRYPT_BLOWFISH == 1)
echo "Blowfish: ".crypt("hiox india");
Standard DES: $1$uK..fl2.$MOB0iNfMOiXYhVyj9yCLX0
In the above example, results for the supported algorithm Standard DES, MD5 is returned.