PHP Class phpseclib\Crypt\TripleDES

Author: Jim Wigginton ([email protected])
Inheritance: extends phpseclib\Crypt\DES
Show file Open project: phpseclib/phpseclib Class Usage Examples

Public Properties

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()

Public Methods

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

Method Details

__construct() public method

Determines whether or not the mcrypt or OpenSSL extensions should be used. $mode could be: - \phpseclib\Crypt\Common\BlockCipher::MODE_ECB - \phpseclib\Crypt\Common\BlockCipher::MODE_CBC - \phpseclib\Crypt\Common\BlockCipher::MODE_CTR - \phpseclib\Crypt\Common\BlockCipher::MODE_CFB - \phpseclib\Crypt\Common\BlockCipher::MODE_OFB - \phpseclib\Crypt\TripleDES::MODE_3CB
See also: phpseclib\Crypt\DES::__construct()
See also: phpseclib\Crypt\Common\SymmetricKey::__construct()
public __construct ( integer $mode )
$mode integer

_setupKey() public method

Creates the key schedule
See also: phpseclib\Crypt\DES::_setupKey()
See also: phpseclib\Crypt\Common\SymmetricKey::_setupKey()
public _setupKey ( )

decrypt() public method

Decrypts a message.
See also: phpseclib\Crypt\Common\SymmetricKey::decrypt()
public decrypt ( string $ciphertext ) : string
$ciphertext string
return string $plaintext

disableContinuousBuffer() public method

The default behavior.
See also: phpseclib\Crypt\Common\SymmetricKey::disableContinuousBuffer()
See also: self::enableContinuousBuffer()

enableContinuousBuffer() public method

Say you have a 16-byte plaintext $plaintext. Using the default behavior, the two following code snippets will yield different outputs: 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 also: phpseclib\Crypt\Common\SymmetricKey::enableContinuousBuffer()
See also: self::disableContinuousBuffer()

encrypt() public method

Encrypts a message.
See also: phpseclib\Crypt\Common\SymmetricKey::encrypt()
public encrypt ( string $plaintext ) : string
$plaintext string
return string $cipertext

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::__construct()
public isValidEngine ( integer $engine ) : boolean
$engine integer
return boolean

setIV() public method

SetIV is not required when \phpseclib\Crypt\Common\SymmetricKey::MODE_ECB is being used.
See also: phpseclib\Crypt\Common\SymmetricKey::setIV()
public setIV ( string $iv )
$iv string

setKey() public method

Triple DES can use 128-bit (eg. strlen($key) == 16) or 192-bit (eg. strlen($key) == 24) keys. DES also requires that every eighth bit be a parity bit, however, we'll ignore that.
See also: phpseclib\Crypt\DES::setKey()
See also: phpseclib\Crypt\Common\SymmetricKey::setKey()
public setKey ( string $key )
$key string

setKeyLength() public method

Valid key lengths are 128 and 192 bits. If you want to use a 64-bit key use DES.php
public setKeyLength ( integer $length )
$length integer

setPreferredEngine() public method

Sets the internal crypt engine
See also: phpseclib\Crypt\Common\SymmetricKey::__construct()
See also: phpseclib\Crypt\Common\SymmetricKey::setPreferredEngine()
public setPreferredEngine ( integer $engine ) : integer
$engine integer
return integer

Property Details

$cfb_init_len public property

Optimizing value while CFB-encrypting
See also: phpseclib\Crypt\Common\SymmetricKey::cfb_init_len
public int $cfb_init_len
return integer

$cipher_name_mcrypt public property

The mcrypt specific name of the cipher
See also: phpseclib\Crypt\DES::cipher_name_mcrypt
See also: phpseclib\Crypt\Common\SymmetricKey::cipher_name_mcrypt
public string $cipher_name_mcrypt
return string

$des public property

Used only if $mode_3cbc === true
public array $des
return array

$key_length public property

Key Length (in bytes)
See also: phpseclib\Crypt\TripleDES::setKeyLength()
public int $key_length
return integer

$key_length_max public property

max possible size of $key
See also: self::setKey()
See also: phpseclib\Crypt\DES::setKey()
public string $key_length_max
return string

$mode_3cbc public property

Internal flag whether using self::MODE_3CBC or not
public bool $mode_3cbc
return boolean

$password_default_salt public property

The default salt used by setPassword()
See also: phpseclib\Crypt\Common\SymmetricKey::password_default_salt
See also: phpseclib\Crypt\Common\SymmetricKey::setPassword()
public string $password_default_salt
return string