Crypt_RC4()
__destruct()
_crypt()
decrypt()
disableContinuousBuffer()
disablePadding()
enableContinuousBuffer()
enablePadding()
encrypt()
setIV()
setKey()
setMCrypt()
$continuousBuffer
$decryptIndex
$decryptStream
$encryptIndex
$encryptStream
$key
$mcrypt
$mode
Pure-PHP implementation of RC4.
author | Jim Wigginton |
---|---|
version | 0.1.0 |
access | public |
package | Crypt_RC4 |
__destruct()
Will be called, automatically, if you're using PHP5. If you're using PHP4, call it yourself. Only really needs to be called if mcrypt is being used.
access | public |
---|
_crypt(String $text, Integer $mode)
see | \global\Crypt_RC4::encrypt() |
---|---|
see | \global\Crypt_RC4::decrypt() |
access | private |
String
Integer
decrypt(String $ciphertext)
$this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)). Atleast if the continuous buffer is disabled.
see | \global\Crypt_RC4::_crypt() |
---|---|
access | public |
String
disableContinuousBuffer()
The default behavior.
see | \global\Crypt_RC4::enableContinuousBuffer() |
---|---|
access | public |
disablePadding()
see | \global\Crypt_RC4::enablePadding() |
---|---|
access | public |
enableContinuousBuffer()
Say you have a 16-byte plaintext $plaintext. Using the default behavior, the two following code snippets will yield different outputs:
echo $rc4->encrypt(substr($plaintext, 0, 8));
echo $rc4->encrypt(substr($plaintext, 8, 8));
echo $rc4->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:
$rc4->encrypt(substr($plaintext, 0, 8));
echo $rc4->decrypt($des->encrypt(substr($plaintext, 8, 8)));
echo $rc4->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 | \global\Crypt_RC4::disableContinuousBuffer() |
---|---|
access | public |
enablePadding()
Since RC4 is a stream cipher and not a block cipher, no padding is necessary. The only reason this function is included is so that you can switch between a block cipher and a stream cipher transparently.
see | \global\Crypt_RC4::disablePadding() |
---|---|
access | public |
encrypt(String $plaintext)
see | \global\Crypt_RC4::_crypt() |
---|---|
access | public |
String
setIV(String $iv)
Some protocols, such as WEP, prepend an "initialization vector" to the key, effectively creating a new key [1]. If you need to use an initialization vector in this manner, feel free to prepend it to the key, yourself, before calling setKey().
[1] WEP's initialization vectors (IV's) are used in a somewhat insecure way. Since, in that protocol, the IV's are relatively easy to predict, an attack described by Scott Fluhrer, Itsik Mantin, and Adi Shamir can be used to quickly guess at the rest of the key. The following links elaborate:
http://www.rsa.com/rsalabs/node.asp?id=2009 http://en.wikipedia.org/wiki/Related_key_attack
see | \global\Crypt_RC4::setKey() |
---|---|
access | public |
String
setKey(String $key)
Keys can be between 1 and 256 bytes long. If they are longer then 256 bytes, the first 256 bytes will be used. If no key is explicitly set, it'll be assumed to be a single null byte.
access | public |
---|
String
setMCrypt(\optional $algorithm_directory, \optional $mode_directory)
(optional)
If MCrypt is being used, empty strings will be used, unless otherwise specified.
link | http://php.net/function.mcrypt-module-open#function.mcrypt-module-open |
---|---|
access | public |
\optional
Integer $algorithm_directory
\optional
Integer $mode_directory
$continuousBuffer : Boolean
see | \global\Crypt_RC4::enableContinuousBuffer() |
---|---|
access | private |
$decryptIndex : Integer
see | \global\Crypt_RC4::_crypt() |
---|---|
access | private |
$decryptStream : Array
If CRYPT_RC4_MODE == CRYPT_RC4_MODE_MCRYPT, this will be equal to the mcrypt object
see | \global\Crypt_RC4::setKey() |
---|---|
access | private |
$encryptIndex : Integer
see | \global\Crypt_RC4::_crypt() |
---|---|
access | private |
$encryptStream : Array
If CRYPT_RC4_MODE == CRYPT_RC4_MODE_MCRYPT, this will be equal to the mcrypt object
see | \global\Crypt_RC4::setKey() |
---|---|
access | private |
$key : String
see | \global\Crypt_RC4::setKey() |
---|---|
access | private |
$mcrypt : Array
see | \global\Crypt_RC4::setMCrypt() |
---|---|
access | private |
$mode : Integer
Only used if CRYPT_RC4_MODE == CRYPT_RC4_MODE_MCRYPT. Only possible values are MCRYPT_RC4 or MCRYPT_ARCFOUR.
see | \global\Crypt_RC4::Crypt_RC4() |
---|---|
access | private |