Encryption error after changing the version of php

April 24, 2016 2.7k views

I changed php version of 7 to 5.6, and appeared here such error.

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

How to fix it?

1 Answer

I am also facing something similar issue and found the following answer on the Internet. Check if it make sense to you.

In previous versions keys and IVs were padded with ’\0’ bytes to the next valid size which is not in the later versions. Try the following solutions -

1) Pad the key with “\0” which previous versions were doing for you


2) in case option 1 does not work try the following functions

function pad_key($key){
    // key is too large
    if(strlen($key) > 32) return false;

    // set sizes
    $sizes = array(16,24,32);

    // loop through sizes and pad key
    foreach($sizes as $s){
        while(strlen($key) < $s) $key = $key."\0";
        if(strlen($key) == $s) break; // finish if the key matches a size

    // return
    return $key;

Source: Possible reason of Encryption error after changing the PHP Version

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!