PHP crypt Function

What is crypt Function and how it is used in string?

Explanation

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$

Syntax:


crypt(str,salt)

In the above syntax "str" specifies the string to be encrypted,"salt" is the number of characters to be encoded.

Example :


<?php
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");
}
?>
Result :

Standard DES: $1$uK..fl2.$MOB0iNfMOiXYhVyj9yCLX0
MD5: $1$6D3.Vl2.$f7oVTfnVpCWi0ufek6q5x1

In the above example, results for the supported algorithm Standard DES, MD5 is returned.

PHP Topics


Ask Questions

Ask Question