mcrypt_get_block_size():模块初始化失败 - 函数出错

时间:2017-02-21 21:35:33

标签: php mcrypt

我正在尝试创建一个可以加密字符串的函数。我有以下代码但是我收到了错误。

$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():第41行上的模块初始化失败”,这是$ block = mcrypt_get_block_size('ISO-8859-1','ecb');

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您将'ISO-8859-1'作为第一个参数传递给mcrypt_get_block_size

您可能打算将MCRYPT_RIJNDAEL_128作为第一个参数传递。

请注意,mcrypt已被弃用,因此您应该查看其他解决方案。如果有其他选择,请查看this question