phpseclib\Crypt\Rijndael::setKey PHP Method

setKey() public method

Rijndael supports five different key lengths
See also: setKeyLength()
public setKey ( string $key )
$key string
    function setKey($key)
    {
        switch (strlen($key)) {
            case 16:
            case 20:
            case 24:
            case 28:
            case 32:
                break;
            default:
                throw new \LengthException('Key of size ' . strlen($key) . ' not supported by this algorithm. Only keys of sizes 16, 20, 24, 28 or 32 are supported');
        }
        parent::setKey($key);
    }

Usage Example

Example #1
0
 public static function decrypt($encryptionKey, $encryptedString, $blockType = 'CBC', $urlSafe = false)
 {
     if ($urlSafe) {
         $data = Base64URLSafe::urlsafe_b64decode($encryptedString);
     } else {
         $data = base64_decode($encryptedString);
     }
     switch ($blockType) {
         case 'CBC':
             $cipher = new Rijndael(Rijndael::MODE_CBC);
             $cipher->setKey($encryptionKey);
             // Split the IV from the ciphertext
             $iv = substr($data, 0, $cipher->getBlockLength() >> 3);
             $cipherText = substr($data, $cipher->getBlockLength() >> 3, strlen($encryptedString));
             $cipher->setIV($iv);
             break;
         case 'ECB':
             $cipher = new Rijndael(Rijndael::MODE_ECB);
             $cipher->setKey($encryptionKey);
             $cipherText = $data;
             break;
         default:
             throw new \Exception('Unknown encryption blocktype: ' . $blockType, 500);
             break;
     }
     return $cipher->decrypt($cipherText);
 }
All Usage Examples Of phpseclib\Crypt\Rijndael::setKey