phpseclib\Crypt\TripleDES::encrypt PHP Method

encrypt() public method

Encrypts a message.
See also: phpseclib\Crypt\Common\SymmetricKey::encrypt()
public encrypt ( string $plaintext ) : string
$plaintext string
return string $cipertext
    function encrypt($plaintext)
    {
        // parent::en/decrypt() is able to do all the work for all modes and keylengths,
        // except for: self::MODE_3CBC (inner chaining CBC) with a key > 64bits
        // if the key is smaller then 8, do what we'd normally do
        if ($this->mode_3cbc && strlen($this->key) > 8) {
            return $this->des[2]->encrypt($this->des[1]->decrypt($this->des[0]->encrypt($this->_pad($plaintext))));
        }
        return parent::encrypt($plaintext);
    }

Usage Example

Example #1
0
 public function testInnerChaining()
 {
     // regular CBC returns
     //           e089b6d84708c6bc80be6c2da82bd19a79ffe11f02933ac1
     $expected = 'e089b6d84708c6bc6f04c8971121603d7be2861efae0f3f5';
     $des = new TripleDES(TripleDES::MODE_3CBC);
     $des->setKey('abcdefghijklmnopqrstuvwx');
     foreach ($this->engines as $engine => $engineName) {
         $des->setPreferredEngine($engine);
         if (!$des->isValidEngine($engine)) {
             self::markTestSkipped('Unable to initialize ' . $engineName . ' engine');
         }
         $result = bin2hex($des->encrypt(str_repeat('a', 16)));
         $this->assertEquals($result, $expected, "Failed asserting inner chainin worked correctly in {$engineName} engine");
     }
 }
All Usage Examples Of phpseclib\Crypt\TripleDES::encrypt