note 69434 deleted from ref.mcrypt by sean
| From: | sean@php.net | Date: | Wed, 06 Sep 2006 23:48:10 +0000 |
| Subject: | note 69434 deleted from ref.mcrypt by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116786@lists.php.net to get a copy of this message | ||
Note Submitter:
----
For those looking a mysql_aes_decrypt, I was able to create this method, referencing rolf's
aes_encrypt below. Since the aes_encrypt right bads n * blocksize with chr( 0 to 16 ), but is random
based on the input string, we first decrypt the text, then rtrim chr(0 .. 16) depending on it's
initial length :)
mysql AES_DECRYPT() compatibly function for PHP :
function mysql_aes_decrypt( $val, $ky = 's0ftd0c2oo6' )
{
$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.