Class: Crypt_Rijndael
Source Location: /lib/3rdParty/phpseclib/Crypt/Rijndael.php
Pure-PHP implementation of Rijndael.
Author(s):
Version:
|
|
Class Details
Class Methods
constructor Crypt_Rijndael [line 369]
Crypt_Rijndael Crypt_Rijndael(
[optional
$mode = CRYPT_RIJNDAEL_MODE_CBC])
|
|
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.
Tags:
Parameters:
method decrypt [line 663]
void decrypt(
String
$ciphertext)
|
|
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.
Tags:
Overridden in child classes as:
- Crypt_AES::decrypt()
- Decrypts a message.
Parameters:
method disableContinuousBuffer [line 1216]
void disableContinuousBuffer(
)
|
|
Treat consecutive packets as if they are a discontinuous buffer. The default behavior.
Tags:
method disablePadding [line 1106]
Do not pad packets.
Tags:
method enableContinuousBuffer [line 1203]
void enableContinuousBuffer(
)
|
|
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($plaintext);
The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates another, as demonstrated with the following:
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.
Tags:
method enablePadding [line 1095]
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)
Tags:
method encrypt [line 611]
void encrypt(
String
$plaintext)
|
|
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.
Tags:
Overridden in child classes as:
- Crypt_AES::encrypt()
- Encrypts a message.
Parameters:
method setBlockLength [line 541]
void setBlockLength(
Integer
$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.
Tags:
Overridden in child classes as:
- Crypt_AES::setBlockLength()
- Dummy function
Parameters:
method setIV [line 503]
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.
Tags:
Parameters:
method setKey [line 488]
void setKey(
String
$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.
Tags:
Parameters:
method setKeyLength [line 517]
void setKeyLength(
Integer
$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.
Tags:
Parameters:
method _generate_xor [line 566]
void _generate_xor(
Integer
$length,
&$iv, String
$iv)
|
|
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.
Tags:
Parameters:
|
|