Property | Type | Description | |
---|---|---|---|
$cfb_init_len | integer | Optimizing value while CFB-encrypting | |
$cipher_name_mcrypt | string | The mcrypt specific name of the cipher | |
$des | array | Used only if $mode_3cbc === true | |
$key_length | integer | Key Length (in bytes) | |
$key_length_max | string | max possible size of $key | |
$mode_3cbc | boolean | Internal flag whether using self::MODE_3CBC or not | |
$password_default_salt | string | The default salt used by setPassword() |
Method | Description | |
---|---|---|
__construct ( integer $mode ) | Default Constructor. | |
_setupKey ( ) | Creates the key schedule | |
decrypt ( string $ciphertext ) : string | Decrypts a message. | |
disableContinuousBuffer ( ) | Treat consecutive packets as if they are a discontinuous buffer. | |
enableContinuousBuffer ( ) | Treat consecutive "packets" as if they are a continuous buffer. | |
encrypt ( string $plaintext ) : string | Encrypts a message. | |
isValidEngine ( integer $engine ) : boolean | Test for engine validity | |
setIV ( string $iv ) | Sets the initialization vector. | |
setKey ( string $key ) | Sets the key. | |
setKeyLength ( integer $length ) | Sets the key length. | |
setPreferredEngine ( integer $engine ) : integer | Sets the internal crypt engine |
public __construct ( integer $mode ) | ||
$mode | integer |
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. public enableContinuousBuffer ( ) |
public isValidEngine ( integer $engine ) : boolean | ||
$engine | integer | |
return | boolean |
public setKeyLength ( integer $length ) | ||
$length | integer |
public setPreferredEngine ( integer $engine ) : integer | ||
$engine | integer | |
return | integer |
public int $cfb_init_len | ||
return | integer |
public string $cipher_name_mcrypt | ||
return | string |
public string $key_length_max | ||
return | string |
public bool $mode_3cbc | ||
return | boolean |
public string $password_default_salt | ||
return | string |