import console;
import php;
php.code =/***
//AES加密
function aes_encrypt($encryptKey,$encryptStr) {
$localIV = $encryptKey;
$encryptKey = $encryptKey;
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
mcrypt_generic_init($module, $encryptKey, $localIV);
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$pad = $block - (strlen($encryptStr) % $block);
$encryptStr .= str_repeat(chr($pad), $pad);
$encrypted = mcrypt_generic($module, $encryptStr);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
return base64_encode($encrypted);
}
//AES解密
function aes_decrypt($encryptKey,$encryptStr) {
$localIV = $encryptKey;
$encryptKey = $encryptKey;
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
mcrypt_generic_init($module, $encryptKey, $localIV);
$encryptedData = base64_decode($encryptStr);
$encryptedData = mdecrypt_generic($module, $encryptedData);
$e = ord($encryptedData[strlen($encryptedData)-1]);
if($e<=16)$encryptedData=substr($encryptedData, 0,strlen($encryptedData)-$e);
return $encryptedData;
}
$result = aes_encrypt("1234567812345678",'Test String');
$decryptString = aes_decrypt("1234567812345678",$result);
echo $result;
echo $decryptString;
***/
php.print = function( msg ) {
console.log("echo:", msg)
}
php.exec( php.code );
console.pause();
|