PHP Class phpseclib\Crypt\TripleDES

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

Méthodes publiques

Свойство 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()

Méthodes publiques

Méthode 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 méthode

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 méthode

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

decrypt() public méthode

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

disableContinuousBuffer() public méthode

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

enableContinuousBuffer() public méthode

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 méthode

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

isValidEngine() public méthode

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
Résultat boolean

setIV() public méthode

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 méthode

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 méthode

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 méthode

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
Résultat integer

Property Details

$cfb_init_len public_oe property

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

$cipher_name_mcrypt public_oe 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
Résultat string

$des public_oe property

Used only if $mode_3cbc === true
public array $des
Résultat array

$key_length public_oe property

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

$key_length_max public_oe property

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

$mode_3cbc public_oe property

Internal flag whether using self::MODE_3CBC or not
public bool $mode_3cbc
Résultat boolean

$password_default_salt public_oe 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
Résultat string