note 62850 modified in ref.mcrypt by danbrown
| From: | danbrown@php.net | Date: | Mon, 13 Dec 2010 16:23:29 +0000 |
| Subject: | note 62850 modified in ref.mcrypt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174857@lists.php.net to get a copy of this message | ||
mysql AES_ENCRYPT() compatibly function for PHP :
<?php
function mysql_aes_encrypt($val,$ky) {
$mode=MCRYPT_MODE_ECB;
$enc=MCRYPT_RIJNDAEL_128;
$val=str_pad($val, (16*(floor(strlen($val) / 16)+(strlen($val) % 16==0?2:1))), chr(16-(strlen($val)
% 16)));
return mcrypt_encrypt($enc, $ky, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode),
MCRYPT_DEV_URANDOM));
}
?>
Please note that if the strlen($ky)>16 then this function will not be compatible.
--was--
mysql AES_ENCRYPT() compatibly function for PHP :
function mysql_aes_encrypt($val,$ky) {
$mode=MCRYPT_MODE_ECB;
$enc=MCRYPT_RIJNDAEL_128;
$val=str_pad($val, (16*(floor(strlen($val) / 16)+(strlen($val) % 16==0?2:1))), chr(16-(strlen($val)
% 16)));
return mcrypt_encrypt($enc, $ky, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode),
MCRYPT_DEV_URANDOM));
}
Please note that if the strlen($ky)>16 then this function will not be compatible.
http://php.net/manual/en/ref.mcrypt.php