Blesta
  • Package
  • Class
  • Tree
  • Deprecated

Packages

  • blesta
    • app
      • components
        • events
          • default
      • controllers
      • models
    • components
      • auth
      • delivery
        • interfax
        • postal
          • methods
      • download
      • email
      • exchange
        • rates
          • foxrate
          • google
            • finance
          • yahoo
            • finance
      • gateway
        • payments
      • gateways
      • invoice
        • delivery
        • templates
      • json
      • modules
      • net
        • http
        • net
          • amazon
            • s3
          • geo
            • ip
      • plugins
      • recaptcha
      • security
      • session
        • cart
      • settingscollection
      • upgrades
      • upload
      • vcard
    • helpers
      • currency
        • format
      • data
        • structure
          • array
          • string
      • text
        • parser
  • com
    • tecnick
      • tcpdf
        • blesta
          • components
            • invoice
              • templates
                • quickbooks
                  • invoice
                • templates
                  • default
  • Crypt
    • AES
    • DES
    • Hash
    • Random
    • RC4
    • Rijndael
    • RSA
    • TerraDES
  • File
    • ANSI
    • ASN1
    • X509
  • Math
    • BigInteger
  • minPHP
    • components
      • input
      • record
    • helpers
      • color
      • data
        • structure
      • date
      • html
      • xml
    • lib
  • Net
    • SFTP
    • SSH1
    • SSH2
  • None
  • PHP
  • PHPMailer
  • Services
    • JSON
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Crypt_TripleDES

Class Crypt_TripleDES

Pure-PHP implementation of Triple DES.

Package: Crypt\TerraDES
Copyright: MMVII Jim Wigginton
License: MIT License
Author: Jim Wigginton <terrafrost@php.net>
Version: 0.1.0
Located at vendors/phpseclib/Crypt/TripleDES.php

Methods summary

public Crypt_TripleDES
# Crypt_TripleDES( optional $mode = CRYPT_DES_MODE_CBC )

Default Constructor.

Default Constructor.

Determines whether or not the mcrypt extension should be used. $mode should only, at present, be CRYPT_DES_MODE_ECB or CRYPT_DES_MODE_CBC. If not explictly set, CRYPT_DES_MODE_CBC will be used.

Parameters

$mode
optional
Integer $mode

Returns

Crypt_TripleDES
public
# setKey( String $key )

Sets the key.

Sets the key.

Keys can be of any length. Triple DES, itself, can use 128-bit (eg. strlen($key) == 16) or 192-bit (eg. strlen($key) == 24) keys. This function pads and truncates $key as appropriate.

DES also requires that every eighth bit be a parity bit, however, we'll ignore that.

If the key is not explicitly set, it'll be assumed to be all zero's.

Parameters

$key
String
$key
public
# setPassword( String $password, optional $method = 'pbkdf2' )

Sets the password.

Sets the password.

Depending on what $method is set to, setPassword()'s (optional) parameters are as follows: pbkdf2: $hash, $salt, $method

Parameters

$password
String
$password
$method
optional
String $method
public
# setIV( String $iv )

Sets the initialization vector. (optional)

Sets the initialization vector. (optional)

SetIV is not required when CRYPT_DES_MODE_ECB is being used. If not explictly set, it'll be assumed to be all zero's.

Parameters

$iv
String
$iv
public
# _generate_xor( Integer $length, String & $iv )

Generate CTR XOR encryption key

Generate CTR XOR encryption key

Encrypt the output of this and XOR it against the ciphertext / plaintext to get the plaintext / ciphertext in CTR mode.

Parameters

$length
Integer
$length
$iv
String
$iv

See

Crypt_TripleDES::decrypt()
Crypt_TripleDES::encrypt()
public
# encrypt( String $plaintext )

Encrypts a message.

Encrypts a message.

Parameters

$plaintext
String
$plaintext
public
# decrypt( String $ciphertext )

Decrypts a message.

Decrypts a message.

Parameters

$ciphertext
String
$ciphertext
public
# enableContinuousBuffer( )

Treat consecutive "packets" as if they are a continuous buffer.

Treat consecutive "packets" as if they are a continuous buffer.

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

Crypt_TripleDES::disableContinuousBuffer()
public
# disableContinuousBuffer( )

Treat consecutive packets as if they are a discontinuous buffer.

Treat consecutive packets as if they are a discontinuous buffer.

The default behavior.

See

Crypt_TripleDES::enableContinuousBuffer()
public
# enablePadding( )

Pad "packets".

Pad "packets".

DES works by encrypting eight bytes at a time. If you ever need to encrypt or decrypt something that's not a multiple of eight, it becomes necessary to pad the input so that it's length is a multiple of eight.

Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH1, where "packets" are padded with random bytes before being encrypted. Unpad these packets and you risk stripping away characters that shouldn't be stripped away. (SSH knows how many bytes are added because the length is transmitted separately)

See

Crypt_TripleDES::disablePadding()
public
# disablePadding( )

Do not pad packets.

Do not pad packets.

See

Crypt_TripleDES::enablePadding()
public
# _pad( mixed $text )

Pads a string

Pads a string

Pads a string using the RSA PKCS padding standards so that its length is a multiple of the blocksize (8). 8 - (strlen($text) & 7) bytes are added, each of which is equal to chr(8 - (strlen($text) & 7)

If padding is disabled and $text is not a multiple of the blocksize, the string will be padded regardless and padding will, hence forth, be enabled.

See

Crypt_TripleDES::_unpad()
public
# _unpad( mixed $text )

Unpads a string

Unpads a string

If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong and false will be returned.

See

Crypt_TripleDES::_pad()
public String
# _string_shift( String & $string, optional $index = 1 )

String Shift

String Shift

Inspired by array_shift

Parameters

$string
String
$string
$index
optional
Integer $index

Returns

String

Magic methods summary

Properties summary

public String $key
#

The Three Keys

The Three Keys

See

Crypt_TripleDES::setKey()
public Integer $mode
#

The Encryption Mode

The Encryption Mode

See

Crypt_TripleDES::Crypt_TripleDES()
public Boolean $continuousBuffer
#

Continuous Buffer status

Continuous Buffer status

See

Crypt_TripleDES::enableContinuousBuffer()
public Boolean $padding
#

Padding status

Padding status

See

Crypt_TripleDES::enablePadding()
public String $iv
#

The Initialization Vector

The Initialization Vector

See

Crypt_TripleDES::setIV()
public String $encryptIV
#

A "sliding" Initialization Vector

A "sliding" Initialization Vector

See

Crypt_TripleDES::enableContinuousBuffer()
public String $decryptIV
#

A "sliding" Initialization Vector

A "sliding" Initialization Vector

See

Crypt_TripleDES::enableContinuousBuffer()
public Array $des
#

The Crypt_DES objects

The Crypt_DES objects

public String $enmcrypt
#

mcrypt resource for encryption

mcrypt resource for encryption

The mcrypt resource can be recreated every time something needs to be created or it can be created just once. Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.

See

Crypt_TripleDES::encrypt()
public String $demcrypt
#

mcrypt resource for decryption

mcrypt resource for decryption

The mcrypt resource can be recreated every time something needs to be created or it can be created just once. Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.

See

Crypt_TripleDES::decrypt()
public Boolean $enchanged
#

Does the enmcrypt resource need to be (re)initialized?

Does the enmcrypt resource need to be (re)initialized?

See

Crypt_TripleDES::setKey()
Crypt_TripleDES::setIV()
public Boolean $dechanged
#

Does the demcrypt resource need to be (re)initialized?

Does the demcrypt resource need to be (re)initialized?

See

Crypt_TripleDES::setKey()
Crypt_TripleDES::setIV()
public Boolean $paddable
#

Is the mode one that is paddable?

Is the mode one that is paddable?

See

Crypt_TripleDES::Crypt_TripleDES()
public String $enbuffer
#

Encryption buffer for CTR, OFB and CFB modes

Encryption buffer for CTR, OFB and CFB modes

See

Crypt_TripleDES::encrypt()
public String $debuffer
#

Decryption buffer for CTR, OFB and CFB modes

Decryption buffer for CTR, OFB and CFB modes

See

Crypt_TripleDES::decrypt()
public String $ecb
#

mcrypt resource for CFB mode

mcrypt resource for CFB mode

See

Crypt_TripleDES::encrypt()
Crypt_TripleDES::decrypt()
Blesta API documentation generated by ApiGen 2.8.0