Thursday, 25 September 2014

crypt in PHP

The PHP crypt() function is utilized to return encrypted string using DES, Blowfish algorithm.

Syntax:

crypt(str,salt)
 
Parameters Description: 
str : Required. Defines the input string.
salt : Optional. A string used to build the amount of characters encoded, to make the encoding more secure.
if salt argument not provided, the behavior is characterized by the algorithm implementation and can unexpected results.

Note : There is no decrypt function. The PHP crypt() function utilizes a one-way algorithm.

Example:

<?php 
echo "here we will test the different algorithms (output will be depending on the operating system) :<br />";
if(CRYPT_STD_DES == 1){
   echo "Standard DES: ".crypt("good morning")."\n<br />";
}else{
   echo "Standard DES not supported.\n<br />";
}
if(CRYPT_EXT_DES == 1){
   echo "Extended DES: ".crypt("good morning")."\n<br />";
}else{
   echo "Extended DES not supported. \n<br />";
}
if(CRYPT_MD5 == 1){
   echo "MD5: ".crypt("good morning")."\n<br />";
}else{
   echo "MD5 not supported. \n<br />";
}
if(CRYPT_BLOWFISH == 1){
   echo "Blowfish: ".crypt("good morning")."\n<br />";
}
else{
   echo "Blowfish DES not supported.";
}
?>

O/P:

here we will test the different algorithms (output will be depending on the operating system) :

Standard DES: $1$kH1.dd3.$B9H/VcAfaDHXCcioeO1E11

Extended DES: $1$in0.DK3.$h5n9DQou5ysf5MI28iXSX1

MD5: $1$Q.1.ZE1.$xkeQ3DrwGwtkO2xsEc/gA/

Blowfish: $1$ub0.fi1.$veDAf3Tx0TigArNG2ksc/0

0 comments:

Post a Comment