douci1615 2015-09-08 01:23
浏览 112
已采纳

mcrypt在Windows / IIS上的PHP 5.6中不起作用

I have been making heavy use of mcrypt in my php app for years, both on win/IIS and on linux. Although I'm running PHP 5.4.28 on my linux server, I just upgraded to PHP 5.6.11 on my windows 8.1 IIS box. And mcrypt no longer works. It doesn't throw any errors that I can see; it just doesn't work. Here is my encryption function:

function Encrypt($text){ 
    global $salt;
    if($text != "")
        return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));  
    else
        return "";
}   

This works fine on my linux server, but returns blank on my local windows box. From what I have read, mcrypt is built into php 5.6 for windows, so there should be no fiddling with extensions or ini file.

What am I missing?

  • 写回答

4条回答 默认 最新

  • dongque6377 2015-09-15 01:46
    关注

    PHP 5.6 has stronger encryption requirements than 5.4. In 5.6 you'll get this warning, which is really an error because it actually causes encryptions and decryptions to fail:

    Warning: mcrypt_encrypt(): Key of size xx not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported.

    ...where "xx" is the length of your salt value. So the salt value has to be exactly 16, 24, or 32 characters in length.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥100 AT89C52单片机C语言调试之后再回答
  • ¥15 AT89C52单片机C语言串口助手发送数据包返回值
  • ¥15 C++数组中找第二小的数字程序纠错
  • ¥50 MATLAB APP 制作出现问题
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e
  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度