php5.5.9
-----------------------
$output = "test php !!"
$key = "abcd123456789";
$output = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $output, MCRYPT_MODE_CBC);
$output = bin2hex($output);
echo $output;
---------------------------------------------------
php5.6 之后,mcrypt_encrypt 必须要 带 第五个参数 $iv, 但是加密出来的结果也可以和5.5的行为一样
1. php5.6 中 key 必须要8,16,32个字符;(之前的只有15个字符,php5.5其实是自动填 )
2. php5.6 中 iv 必须要 ; (之前的版本, php5.5应该是默认填 16个 (至于是8个, 还是16个,32个,这个是和前面的key的长度有关的!));
所有,基于以上的原因,便有了下面php5.6对应的代码:
--------------------------------------------------------
$output = "test php !!"
$key = "abcd123456789"." ";
$iv = str_repeat(" ", 16);
$output = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $output, MCRYPT_MODE_CBC, $iv);
$output = bin2hex($output);
echo $output;
-------------------------------------------