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_Rijndael

Class Crypt_Rijndael

Pure-PHP implementation of Rijndael.

Direct known subclasses

Crypt_AES

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

Methods summary

public Crypt_Rijndael
# Crypt_Rijndael( optional $mode = CRYPT_RIJNDAEL_MODE_CBC )

Default Constructor.

Default Constructor.

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

Parameters

$mode
optional
Integer $mode

Returns

Crypt_Rijndael
public
# setKey( String $key )

Sets the key.

Sets the key.

Keys can be of any length. Rijndael, itself, requires the use of a key that's between 128-bits and 256-bits long and whose length is a multiple of 32. If the key is less than 256-bits and the key length isn't set, we round the length up to the closest valid key length, padding $key with null bytes. If the key is more than 256-bits, we trim the excess bits.

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

Parameters

$key
String
$key
public
# setIV( String $iv )

Sets the initialization vector. (optional)

Sets the initialization vector. (optional)

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

Parameters

$iv
String
$iv
public
# setKeyLength( Integer $length )

Sets the key length

Sets the key length

Valid key lengths are 128, 160, 192, 224, and 256. If the length is less than 128, it will be rounded up to 128. If the length is greater then 128 and invalid, it will be rounded down to the closest valid amount.

Parameters

$length
Integer
$length
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, $count Set $dkLen by calling setKeyLength()

Parameters

$password
String
$password
$method
optional
String $method
public
# setBlockLength( Integer $length )

Sets the block length

Sets the block length

Valid block lengths are 128, 160, 192, 224, and 256. If the length is less than 128, it will be rounded up to 128. If the length is greater then 128 and invalid, it will be rounded down to the closest valid amount.

Parameters

$length
Integer
$length
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_Rijndael::decrypt()
Crypt_Rijndael::encrypt()
public
# encrypt( String $plaintext )

Encrypts a message.

Encrypts a message.

$plaintext will be padded with additional bytes such that it's length is a multiple of the block size. Other Rjindael implementations may or may not pad in the same manner. Other common approaches to padding and the reasons why it's necessary are discussed in the following URL:

http://www.di-mgt.com.au/cryptopad.html

An alternative to padding is to, separately, send the length of the file. This is what SSH, in fact, does. strlen($plaintext) will still need to be a multiple of 8, however, arbitrary values can be added to make it that length.

Parameters

$plaintext
String
$plaintext

See

Crypt_Rijndael::decrypt()
public
# decrypt( String $ciphertext )

Decrypts a message.

Decrypts a message.

If strlen($ciphertext) is not a multiple of the block size, null bytes will be added to the end of the string until it is.

Parameters

$ciphertext
String
$ciphertext

See

Crypt_Rijndael::encrypt()
public String
# _encryptBlock( String $in )

Encrypts a block

Encrypts a block

Parameters

$in
String
$in

Returns

String
public String
# _decryptBlock( String $in )

Decrypts a block

Decrypts a block

Parameters

$in
String
$in

Returns

String
public
# _setup( )

Setup Rijndael

Setup Rijndael

Validates all the variables and calculates $Nr - the number of rounds that need to be performed - and $w - the key key schedule.

public
# _subWord( mixed $word )

Performs S-Box substitutions

Performs S-Box substitutions

public
# _invSubWord( mixed $word )

Performs inverse S-Box substitutions

Performs inverse S-Box substitutions

public
# enablePadding( )

Pad "packets".

Pad "packets".

Rijndael works by encrypting between sixteen and thirty-two bytes at a time, provided that number is also a multiple of four. If you ever need to encrypt or decrypt something that isn't of the proper length, it becomes necessary to pad the input so that it is of the proper length.

Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH, 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_Rijndael::disablePadding()
public
# disablePadding( )

Do not pad packets.

Do not pad packets.

See

Crypt_Rijndael::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. $block_size - (strlen($text) % $block_size) bytes are added, each of which is equal to chr($block_size - (strlen($text) % $block_size)

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_Rijndael::_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_Rijndael::_pad()
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 32-byte plaintext $plaintext. Using the default behavior, the two following code snippets will yield different outputs:

echo $rijndael->encrypt(substr($plaintext,  0, 16));
echo $rijndael->encrypt(substr($plaintext, 16, 16));
echo $rijndael->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:

$rijndael->encrypt(substr($plaintext, 0, 16));
echo $rijndael->decrypt($des->encrypt(substr($plaintext, 16, 16)));
echo $rijndael->decrypt($des->encrypt(substr($plaintext, 16, 16)));

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_Rijndael() 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_Rijndael::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_Rijndael::enableContinuousBuffer()
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 Integer $mode
#

The Encryption Mode

The Encryption Mode

See

Crypt_Rijndael::Crypt_Rijndael()
public String $key
#

The Key

The Key

See

Crypt_Rijndael::setKey()
public String $iv
#

The Initialization Vector

The Initialization Vector

See

Crypt_Rijndael::setIV()
public String $encryptIV
#

A "sliding" Initialization Vector

A "sliding" Initialization Vector

See

Crypt_Rijndael::enableContinuousBuffer()
public String $decryptIV
#

A "sliding" Initialization Vector

A "sliding" Initialization Vector

See

Crypt_Rijndael::enableContinuousBuffer()
public Boolean $continuousBuffer
#

Continuous Buffer status

Continuous Buffer status

See

Crypt_Rijndael::enableContinuousBuffer()
public Boolean $padding
#

Padding status

Padding status

See

Crypt_Rijndael::enablePadding()
public Boolean $changed
#

Does the key schedule need to be (re)calculated?

Does the key schedule need to be (re)calculated?

See

Crypt_Rijndael::setKey()
Crypt_Rijndael::setBlockLength()
Crypt_Rijndael::setKeyLength()
public Boolean $explicit_key_length
#

Has the key length explicitly been set or should it be derived from the key, itself?

Has the key length explicitly been set or should it be derived from the key, itself?

See

Crypt_Rijndael::setKeyLength()
public Array $w
#

The Key Schedule

The Key Schedule

See

Crypt_Rijndael::_setup()
public Array $dw
#

The Inverse Key Schedule

The Inverse Key Schedule

See

Crypt_Rijndael::_setup()
public Integer $block_size
#

The Block Length

The Block Length

See

Crypt_Rijndael::setBlockLength()
public Integer $Nb
#

The Block Length divided by 32

The Block Length divided by 32

See

Crypt_Rijndael::setBlockLength()
public Integer $key_size
#

The Key Length

The Key Length

See

Crypt_Rijndael::setKeyLength()
public Integer $Nk
#

The Key Length divided by 32

The Key Length divided by 32

See

Crypt_Rijndael::setKeyLength()
public Integer $Nr
#

The Number of Rounds

The Number of Rounds

public Array $c
#

Shift offsets

Shift offsets

public Array $t0
#

Precomputed mixColumns table

Precomputed mixColumns table

See

Crypt_Rijndael::Crypt_Rijndael()
public Array $t1
#

Precomputed mixColumns table

Precomputed mixColumns table

See

Crypt_Rijndael::Crypt_Rijndael()
public Array $t2
#

Precomputed mixColumns table

Precomputed mixColumns table

See

Crypt_Rijndael::Crypt_Rijndael()
public Array $t3
#

Precomputed mixColumns table

Precomputed mixColumns table

See

Crypt_Rijndael::Crypt_Rijndael()
public Array $dt0
#

Precomputed invMixColumns table

Precomputed invMixColumns table

See

Crypt_Rijndael::Crypt_Rijndael()
public Array $dt1
#

Precomputed invMixColumns table

Precomputed invMixColumns table

See

Crypt_Rijndael::Crypt_Rijndael()
public Array $dt2
#

Precomputed invMixColumns table

Precomputed invMixColumns table

See

Crypt_Rijndael::Crypt_Rijndael()
public Array $dt3
#

Precomputed invMixColumns table

Precomputed invMixColumns table

See

Crypt_Rijndael::Crypt_Rijndael()
public Boolean $paddable
#

Is the mode one that is paddable?

Is the mode one that is paddable?

See

Crypt_Rijndael::Crypt_Rijndael()
public String $enbuffer
#

Encryption buffer for CTR, OFB and CFB modes

Encryption buffer for CTR, OFB and CFB modes

See

Crypt_Rijndael::encrypt()
public String $debuffer
#

Decryption buffer for CTR, OFB and CFB modes

Decryption buffer for CTR, OFB and CFB modes

See

Crypt_Rijndael::decrypt()
Blesta API documentation generated by ApiGen 2.8.0