【发布时间】:2017-07-11 17:35:28
【问题描述】:
我正在尝试创建一个可以加密字符串的函数。我有以下代码,但出现错误。
$key = "testkey";
// This is the function that does the encryption. Treat it as a black box. Do not edit!
function encrypt($str, $key){
$block = mcrypt_get_block_size('ISO-8859-1', 'ecb');
$pad = $block - (strlen($str) % $block);
$str .= str_repeat(chr($pad), $pad);
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB));
}
// call the encrypt function and send it the key and the data to encrypt. Store the returned data in the $dataopt variable.
$dataopt = encrypt($rawstring, $key);
错误是“mcrypt_get_block_size(): Module initialization failed on line on line 41”,即 $block = mcrypt_get_block_size('ISO-8859-1', 'ecb');
有什么想法吗?
【问题讨论】: