PHP错误:mcrypt_encrypt():IV参数必须与块大小一样长

时间:2013-11-21 13:21:00

标签: php mcrypt

我收到错误 mcrypt_encrypt():IV参数必须与第二行的blocksize 一样长。

    $data = "Currency=GBP&SuccessURL=test&FailureURL=test&VendorEMail=test&SendEMail=1&eMailMessage=&Amount=&Description=&CustomerName=test test&CustomerEMail=test&BillingSurname=test&BillingFirstnames=test&BillingAddress1=test&BillingAddress2=test&BillingCity=test&BillingPostCode=test&BillingCountry=test&BillingPhone=test&DeliverySurname=test&DeliveryFirstnames=test&DeliveryAddress1=test&DeliveryAddress2=test&DeliveryCity=test&DeliveryPostCode=test&DeliveryCountry=test\u0003\u0003\u0003";
    $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, 'test', $data, MCRYPT_MODE_CBC, 'test');

2 个答案:

答案 0 :(得分:2)

在我的情况下也是同样的错误。我之前使用的是实际密码。但是当我使用加密密码时,它起作用了。在sagepay.php第54行,protected $ encryptPassword =“”。在这里,我使用了加密密码,这是我在测试帐户中获得的。现在它的工作。
这可能会有所帮助。
感谢

答案 1 :(得分:1)

IV参数不是我认为的mcrypt_encrypt()的第4个参数。它实际上是最后一个参数,第五个参数 它在http://php.net/manual/en/function.mcrypt-encrypt.php指定为 iv

此实例的$ data的块大小为16,因此mcrypt_encrypt()中的最后一个参数需要为16个字符长。

blocksize是数据字符串应该可以被整除的数字,否则它的最后一部分需要填充到它就可以被它整除。