note 9517 added to Mcrypt Encryption Functions
| From: | avinesh at stratabase dot com | Date: | Wed, 08 Nov 2000 19:16:56 +0000 |
| Subject: | note 9517 added to Mcrypt Encryption Functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-7504@lists.php.net to get a copy of this message | ||
Under libmcrypt 2.4.x it appears that text is encrypted to high ASCII which can be problematic for
international users. Therefore to correct this problem, I have done the following (which encrypts
text to hex vice-versa):
DEFINE ("Keysize","f23r09aj09f3wqj90");
function enc($data)
{
$td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
$encdata = mcrypt_ecb (MCRYPT_TripleDES,(Keysize), $data, MCRYPT_ENCRYPT, $iv);
$hextext=bin2hex($encdata);
return $hextext;
}
function dec($data)
{
$td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
$dectext = mcrypt_ecb (MCRYPT_TripleDES,(Keysize), hex2bin($data), MCRYPT_DECRYPT,$iv);
return $dectext;
}
function hex2bin($data)
{
$len = strlen($data);
return pack("H" . $len, $data);
}
Regards,
Avinesh
http://www.php.net/manual/ref.mcrypt.php