* echo $des->encrypt(substr($plaintext, 0, 8));
* echo $des->encrypt(substr($plaintext, 8, 8));
*
*
* echo $des->encrypt($plaintext);
*
*
* The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates
* another, as demonstrated with the following:
*
*
* $des->encrypt(substr($plaintext, 0, 8));
* echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8)));
*
*
* echo $des->decrypt($des->encrypt(substr($plaintext, 8, 8)));
*
*
* With the continuous buffer disabled, these would yield the same output. With it enabled, they yield different
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
*
* Put another way, when the continuous buffer is enabled, the state of the \phpseclib\Crypt\DES() object changes after each
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required (SSH uses them),
* however, they are also less intuitive and more likely to cause you problems.
*
* @see \phpseclib\Crypt\Common\SymmetricKey::enableContinuousBuffer()
* @see self::disableContinuousBuffer()
* @access public
*/
public function enableContinuousBuffer()
{
parent::enableContinuousBuffer();
if ($this->mode_3cbc) {
$this->des[0]->enableContinuousBuffer();
$this->des[1]->enableContinuousBuffer();
$this->des[2]->enableContinuousBuffer();
}
}
/**
* Treat consecutive packets as if they are a discontinuous buffer.
*
* The default behavior.
*
* @see \phpseclib\Crypt\Common\SymmetricKey::disableContinuousBuffer()
* @see self::enableContinuousBuffer()
* @access public
*/
public function disableContinuousBuffer()
{
parent::disableContinuousBuffer();
if ($this->mode_3cbc) {
$this->des[0]->disableContinuousBuffer();
$this->des[1]->disableContinuousBuffer();
$this->des[2]->disableContinuousBuffer();
}
}
/**
* Creates the key schedule
*
* @see \phpseclib\Crypt\DES::setupKey()
* @see \phpseclib\Crypt\Common\SymmetricKey::setupKey()
* @access private
*/
protected function setupKey()
{
switch (true) {
// if $key <= 64bits we configure our internal pure-php cipher engine
// to act as regular [1]DES, not as 3DES. mcrypt.so::tripledes does the same.
case strlen($this->key) <= 8:
$this->des_rounds = 1;
break;
// otherwise, if $key > 64bits, we configure our engine to work as 3DES.
default:
$this->des_rounds = 3;
// (only) if 3CBC is used we have, of course, to setup the $des[0-2] keys also separately.
if ($this->mode_3cbc) {
$this->des[0]->setupKey();
$this->des[1]->setupKey();
$this->des[2]->setupKey();
// because $des[0-2] will, now, do all the work we can return here
// not need unnecessary stress parent::setupKey() with our, now unused, $key.
return;
}
}
// setup our key
parent::setupKey();
}
/**
* Sets the internal crypt engine
*
* @see \phpseclib\Crypt\Common\SymmetricKey::__construct()
* @see \phpseclib\Crypt\Common\SymmetricKey::setPreferredEngine()
* @param int $engine
* @access public
*/
public function setPreferredEngine($engine)
{
if ($this->mode_3cbc) {
$this->des[0]->setPreferredEngine($engine);
$this->des[1]->setPreferredEngine($engine);
$this->des[2]->setPreferredEngine($engine);
}
parent::setPreferredEngine($engine);
}
}
PK KiJK!(0)U )U phpseclib/Crypt/RC2.phpnu W+A
* setKey('abcdefgh');
*
* $plaintext = str_repeat('a', 1024);
*
* echo $rc2->decrypt($rc2->encrypt($plaintext));
* ?>
*
*
* @category Crypt
* @package RC2
* @author Patrick Monnerat ' . Base64::encode($primes[1]->toBytes()) . "
\r\n" . '' . Base64::encode($primes[2]->toBytes()) . "\r\n" . '