mcrypt_decrypt() error change key size

后端 未结 8 1642
慢半拍i
慢半拍i 2020-12-06 05:17

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

8条回答
  •  执笔经年
    2020-12-06 05:54

    I went ahead and created a function based on Hanky 웃 Panky's answer.

    This can be used with any key length to make sure it's the correct size.

    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;
    }
    

提交回复
热议问题