mcrypt_encrypt(): Key of size [closed]

雨燕双飞 提交于 2019-12-25 04:42:39

问题


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

http://i.stack.imgur.com/qE1ZD.png

How can I fix this??


回答1:


Used to be if your key was too short that PHP would pad it with \0. This is no longer the case since PHP version 5.6.0. You should check how big required key is for the cipher being used: http://php.net/manual/en/function.mcrypt-get-key-size.php Note there are other ways to check key size, check the documentation. Simple way I understand key size: a string like 'fubar' in ASCII is 5 * 8 = 40 bytes (8 bytes per char). But that's making assumptions about character set in use. Some comments at php.net better explain how to roll a key of correct size:

$key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3");

Here the 64 char string will be converted into 32 byte key because bc is a byte, b0 is another, etc. From http://php.net/manual/en/function.mcrypt-encrypt.php

You can double check number of bytes with strlen(). From above example strlen($key) will print out 32.



来源:https://stackoverflow.com/questions/31125545/mcrypt-encrypt-key-of-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!