phpseclib\Crypt\AES::setKeyLength PHP Method

setKeyLength() public method

Valid key lengths are 128, 192, and 256. Set the link to bool(false) to disable a fixed key length
public setKeyLength ( integer $length )
$length integer
    function setKeyLength($length)
    {
        switch ($length) {
            case 128:
            case 192:
            case 256:
                break;
            default:
                throw new \LengthException('Key of size ' . $length . ' not supported by this algorithm. Only keys of sizes 128, 192 or 256 supported');
        }
        parent::setKeyLength($length);
    }

Usage Example

Example #1
0
 /**
  * Returns a cipher object corresponding to a string
  *
  * @access public
  * @param string $algo
  * @return string
  * @throws \UnexpectedValueException if the encryption algorithm is unsupported
  */
 static function getEncryptionObject($algo)
 {
     $modes = '(CBC|ECB|CFB|OFB|CTR)';
     switch (true) {
         case preg_match("#^AES-(128|192|256)-{$modes}\$#", $algo, $matches):
             $cipher = new AES(self::getEncryptionMode($matches[2]));
             $cipher->setKeyLength($matches[1]);
             return $cipher;
         case preg_match("#^DES-EDE3-{$modes}\$#", $algo, $matches):
             return new TripleDES(self::getEncryptionMode($matches[1]));
         case preg_match("#^DES-{$modes}\$#", $algo, $matches):
             return new DES(self::getEncryptionMode($matches[1]));
         default:
             throw new \UnexpectedValueException('Unsupported encryption algorithmn');
     }
 }
All Usage Examples Of phpseclib\Crypt\AES::setKeyLength