phpseclib\Crypt\RC2::isValidEngine PHP Method

isValidEngine() public method

This is mainly just a wrapper to set things up for \phpseclib\Crypt\Common\SymmetricKey::isValidEngine()
See also: phpseclib\Crypt\Common\SymmetricKey::__construct()
public isValidEngine ( integer $engine ) : boolean
$engine integer
return boolean
    function isValidEngine($engine)
    {
        switch ($engine) {
            case self::ENGINE_OPENSSL:
                if ($this->current_key_length != 128 || strlen($this->orig_key) < 16) {
                    return false;
                }
                $this->cipher_name_openssl_ecb = 'rc2-ecb';
                $this->cipher_name_openssl = 'rc2-' . $this->_openssl_translate_mode();
        }
        return parent::isValidEngine($engine);
    }

Usage Example

Example #1
0
 /**
  * @dataProvider engineVectors
  */
 public function testVectors($engine, $engineName, $key, $keyLen, $plaintext, $ciphertext)
 {
     $rc2 = new RC2();
     $rc2->disablePadding();
     $rc2->setKeyLength($keyLen);
     $rc2->setKey(pack('H*', $key));
     // could also do $rc2->setKey(pack('H*', $key), $keyLen)
     if (!$rc2->isValidEngine($engine)) {
         self::markTestSkipped('Unable to initialize ' . $engineName . ' engine');
     }
     $rc2->setPreferredEngine($engine);
     $result = bin2hex($rc2->encrypt(pack('H*', $plaintext)));
     $this->assertEquals($result, $ciphertext, "Failed asserting that {$plaintext} yielded expected output in {$engineName} engine");
 }