mcrypt_decrypt(): Key of size 15 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported
How Can I fix this issue? my
You can just use str_pad() for this. In its simplest form, this will suffice.
function padKey($key)
{
// Get the current key size
$keySize = strlen($key);
// Set an array containing the valid sizes
$validSizes = [16,24,32];
// Loop through sizes and return correct padded $key
foreach($validSizes as $validSize) {
if ($keySize <= $validSize) return str_pad($key, $validSize, "\0");
}
// Throw an exception if the key is greater than the max size
throw new Exception("Key size is too large");
}
The other answers will do just fine. I'm just taking advantage of the built in PHP function str_pad here instead of appending "\0" in a loop.