Question

Encryption error after changing the version of php

Posted April 24, 2016 2.9k views
PHP

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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
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

$key=$key."\0";

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

Submit an Answer