phpseclib\Crypt\RC2::encrypt PHP Method

encrypt() public method

Mostly a wrapper for \phpseclib\Crypt\Common\SymmetricKey::encrypt, with some additional OpenSSL handling code
See also: self::decrypt()
public encrypt ( string $plaintext ) : string
$plaintext string
return string $ciphertext
    function encrypt($plaintext)
    {
        if ($this->engine == self::ENGINE_OPENSSL) {
            $temp = $this->key;
            $this->key = $this->orig_key;
            $result = parent::encrypt($plaintext);
            $this->key = $temp;
            return $result;
        }
        return parent::encrypt($plaintext);
    }

Usage Example

Exemplo n.º 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");
 }