note 69469 deleted from ref.mcrypt by danbrown
| From: | danbrown@php.net | Date: | Mon, 13 Dec 2010 16:22:59 +0000 |
| Subject: | note 69469 deleted from ref.mcrypt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174856@lists.php.net to get a copy of this message | ||
Note Submitter: pixelchutes AT gmail DOT com
----
For those looking for a mysql_aes_decrypt, I created this method, referencing rolf's
aes_encrypt below. Since the aes_encrypt right-pads N * blocksize with any chr( 0 ) to chr( 16 )
(random based on the input string length) we first decrypt the text, then RTrim chr(0 .. 16)
depending on its trailing ord() value.
mysql AES_DECRYPT() compatibly function for PHP :
<?
function mysql_aes_decrypt( $val, $ky )
{
$mode = MCRYPT_MODE_ECB;
$enc = MCRYPT_RIJNDAEL_128;
$dec = @mcrypt_decrypt($enc, $ky, $val, $mode, @mcrypt_create_iv(
@mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM ) );
return rtrim( $dec, ( ( ord(substr( $dec, strlen( $dec )-1, 1 )) >= 0 and ord(substr(
$dec, strlen( $dec )-1, 1 ) ) <= 16 ) ? chr(ord(substr( $dec, strlen( $dec )-1, 1 ))): null) );
}
?>
Please note that if the strlen($ky)>16 then this function will not be compatible.