mcrypt_encrypt(): Key of size

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

How can I fix this??


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Used to be if your key was too short that PHP would pad it with . 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: 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 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

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

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x