'mcrypt_encrypt(): Key of size 21 not supported by this algorithm

I installed mcrypt-1.0.4 on my remote server but it throws error like

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

     **CODE**
     function encryptCookie($key,$value){
        if(!$value){return false;}
        $text = $value;
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
        return trim(base64_encode($crypttext)); //encode for cookie
     }

     function decryptCookie($key,$value){
      if(!$value){return false;}
      $crypttext = base64_decode($value); //decode cookie
      $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
      $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
      $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv);
      return trim($decrypttext);
     }

Now, what should I do to solve this issue? Any clue anybody?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source