phpseclib\Crypt\Blowfish::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::isValidEngine()
public isValidEngine ( integer $engine ) : boolean
$engine integer
return boolean
    function isValidEngine($engine)
    {
        if ($engine == self::ENGINE_OPENSSL) {
            if ($this->key_length != 16) {
                return false;
            }
            $this->cipher_name_openssl_ecb = 'bf-ecb';
            $this->cipher_name_openssl = 'bf-' . $this->_openssl_translate_mode();
        }
        return parent::isValidEngine($engine);
    }

Usage Example

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