Crypt_RC4

# Class: Crypt_RC4 Source Location: /lib/3rdParty/phpseclib/Crypt/RC4.php
### Class Overview
Pure-PHP implementation of RC4. #### Author(s): Jim Wigginton <terrafrost@php.net> #### Version: 0.1.0 | ### Methods Crypt_RC4 __destruct decrypt disableContinuousBuffer disablePadding enableContinuousBuffer enablePadding encrypt setIV setKey setMCrypt _closeMCrypt
### Class Details [line 95] Pure-PHP implementation of RC4. #### Tags:
author: | Jim Wigginton <terrafrost@php.net>
version: | 0.1.0
access: | public
[ Top ] ### Class Methods ### constructor Crypt_RC4 [line 183]
`Crypt_RC4 Crypt_RC4( optional 0)`
Default Constructor. Determines whether or not the mcrypt extension should be used. #### Tags:
access: | public
#### Parameters:
optional | 0 | Integer $mode
[ Top ] ### destructor __destruct [line 471]
`void __destruct( )`
Class destructor. 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. #### Tags:
access: | public
[ Top ] ### method decrypt [line 307]
`void decrypt( String $ciphertext)`
Decrypts a message. $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)). Atleast if the continuous buffer is disabled. #### Tags:
see: | Crypt_RC4::_crypt()
access: | public
#### Parameters:
String | $ciphertext |
[ Top ] ### method disableContinuousBuffer [line 430]
`void disableContinuousBuffer( )`
Treat consecutive packets as if they are a discontinuous buffer. The default behavior. #### Tags:
see: | Crypt_RC4::enableContinuousBuffer()
access: | public
[ Top ] ### method disablePadding [line 459]
`void disablePadding( )`
Dummy function. #### Tags:
see: | Crypt_RC4::enablePadding()
access: | public
[ Top ] ### method enableContinuousBuffer [line 417]
`void enableContinuousBuffer( )`
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 $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. #### Tags:
see: | Crypt_RC4::disableContinuousBuffer()
access: | public
[ Top ] ### method enablePadding [line 449]
`void enablePadding( )`
Dummy function. 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. #### Tags:
see: | Crypt_RC4::disablePadding()
access: | public
[ Top ] ### method encrypt [line 292]
`void encrypt( String $plaintext)`
Encrypts a message. #### Tags:
see: | Crypt_RC4::_crypt()
access: | public
#### Parameters:
String | $plaintext |
[ Top ] ### method setIV [line 263]
`void setIV( String $iv)`
Dummy function. 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, and 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 #### Tags:
see: | Crypt_RC4::setKey()
access: | public
#### Parameters:
String | $iv |
[ Top ] ### method setKey [line 219]
`void setKey( String $key)`
Sets the 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. #### Tags:
access: | public
#### Parameters:
String | $key |
[ Top ] ### method setMCrypt [line 277]
`void setMCrypt( [optional $algorithm_directory = ''], [optional $mode_directory = ''])`
Sets MCrypt parameters. (optional) If MCrypt is being used, empty strings will be used, unless otherwise specified. #### Tags:
link: | http://php.net/function.mcrypt-module-open#function.mcrypt-module-open
access: | public
#### Parameters:
optional | $algorithm_directory | Integer $algorithm_directory
optional | $mode_directory | Integer $mode_directory
[ Top ] ### method _closeMCrypt [line 483]
`void _closeMCrypt( )`
Properly close the MCrypt objects. [ Top ] Documentation generated on Tue, 22 Nov 2011 16:30:05 +0100 by phpDocumentor 1.4.1