Rev 846 | Rev 1042 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 846 | Rev 874 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | * |
32 | * |
33 | * echo $rc4->decrypt($rc4->encrypt($plaintext)); |
33 | * echo $rc4->decrypt($rc4->encrypt($plaintext)); |
34 | * ?> |
34 | * ?> |
35 | * </code> |
35 | * </code> |
36 | * |
36 | * |
- | 37 | * @category Crypt |
|
- | 38 | * @package RC4 |
|
37 | * @author Jim Wigginton <terrafrost@php.net> |
39 | * @author Jim Wigginton <terrafrost@php.net> |
38 | * @copyright 2007 Jim Wigginton |
40 | * @copyright 2007 Jim Wigginton |
39 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
41 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
40 | * @link http://phpseclib.sourceforge.net |
42 | * @link http://phpseclib.sourceforge.net |
41 | */ |
43 | */ |
Line 45... | Line 47... | ||
45 | use phpseclib3\Crypt\Common\StreamCipher; |
47 | use phpseclib3\Crypt\Common\StreamCipher; |
46 | 48 | ||
47 | /** |
49 | /** |
48 | * Pure-PHP implementation of RC4. |
50 | * Pure-PHP implementation of RC4. |
49 | * |
51 | * |
- | 52 | * @package RC4 |
|
50 | * @author Jim Wigginton <terrafrost@php.net> |
53 | * @author Jim Wigginton <terrafrost@php.net> |
- | 54 | * @access public |
|
51 | */ |
55 | */ |
52 | class RC4 extends StreamCipher |
56 | class RC4 extends StreamCipher |
53 | { |
57 | { |
54 | /** |
58 | /** |
- | 59 | * @access private |
|
55 | * @see \phpseclib3\Crypt\RC4::_crypt() |
60 | * @see \phpseclib3\Crypt\RC4::_crypt() |
56 | */ |
61 | */ |
57 | const ENCRYPT = 0; |
62 | const ENCRYPT = 0; |
58 | 63 | ||
59 | /** |
64 | /** |
- | 65 | * @access private |
|
60 | * @see \phpseclib3\Crypt\RC4::_crypt() |
66 | * @see \phpseclib3\Crypt\RC4::_crypt() |
61 | */ |
67 | */ |
62 | const DECRYPT = 1; |
68 | const DECRYPT = 1; |
63 | 69 | ||
64 | /** |
70 | /** |
65 | * Key Length (in bytes) |
71 | * Key Length (in bytes) |
66 | * |
72 | * |
67 | * @see \phpseclib3\Crypt\RC4::setKeyLength() |
73 | * @see \phpseclib3\Crypt\RC4::setKeyLength() |
68 | * @var int |
74 | * @var int |
- | 75 | * @access private |
|
69 | */ |
76 | */ |
70 | protected $key_length = 128; // = 1024 bits |
77 | protected $key_length = 128; // = 1024 bits |
71 | 78 | ||
72 | /** |
79 | /** |
73 | * The mcrypt specific name of the cipher |
80 | * The mcrypt specific name of the cipher |
74 | * |
81 | * |
75 | * @see \phpseclib3\Crypt\Common\SymmetricKey::cipher_name_mcrypt |
82 | * @see \phpseclib3\Crypt\Common\SymmetricKey::cipher_name_mcrypt |
76 | * @var string |
83 | * @var string |
- | 84 | * @access private |
|
77 | */ |
85 | */ |
78 | protected $cipher_name_mcrypt = 'arcfour'; |
86 | protected $cipher_name_mcrypt = 'arcfour'; |
79 | 87 | ||
80 | /** |
88 | /** |
81 | * The Key |
89 | * The Key |
82 | * |
90 | * |
83 | * @see self::setKey() |
91 | * @see self::setKey() |
84 | * @var string |
92 | * @var string |
- | 93 | * @access private |
|
85 | */ |
94 | */ |
86 | protected $key; |
95 | protected $key; |
87 | 96 | ||
88 | /** |
97 | /** |
89 | * The Key Stream for decryption and encryption |
98 | * The Key Stream for decryption and encryption |
90 | * |
99 | * |
91 | * @see self::setKey() |
100 | * @see self::setKey() |
92 | * @var array |
101 | * @var array |
- | 102 | * @access private |
|
93 | */ |
103 | */ |
94 | private $stream; |
104 | private $stream; |
95 | 105 | ||
96 | /** |
106 | /** |
97 | * Test for engine validity |
107 | * Test for engine validity |
98 | * |
108 | * |
99 | * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() |
109 | * This is mainly just a wrapper to set things up for \phpseclib3\Crypt\Common\SymmetricKey::isValidEngine() |
100 | * |
110 | * |
101 | * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() |
111 | * @see \phpseclib3\Crypt\Common\SymmetricKey::__construct() |
102 | * @param int $engine |
112 | * @param int $engine |
- | 113 | * @access protected |
|
103 | * @return bool |
114 | * @return bool |
104 | */ |
115 | */ |
105 | protected function isValidEngineHelper($engine) |
116 | protected function isValidEngineHelper($engine) |
106 | { |
117 | { |
107 | if ($engine == self::ENGINE_OPENSSL) { |
118 | if ($engine == self::ENGINE_OPENSSL) { |
Line 133... | Line 144... | ||
133 | /** |
144 | /** |
134 | * Sets the key length |
145 | * Sets the key length |
135 | * |
146 | * |
136 | * Keys can be between 1 and 256 bytes long. |
147 | * Keys can be between 1 and 256 bytes long. |
137 | * |
148 | * |
- | 149 | * @access public |
|
138 | * @param int $length |
150 | * @param int $length |
139 | * @throws \LengthException if the key length is invalid |
151 | * @throws \LengthException if the key length is invalid |
140 | */ |
152 | */ |
141 | public function setKeyLength($length) |
153 | public function setKeyLength($length) |
142 | { |
154 | { |
Line 152... | Line 164... | ||
152 | /** |
164 | /** |
153 | * Sets the key length |
165 | * Sets the key length |
154 | * |
166 | * |
155 | * Keys can be between 1 and 256 bytes long. |
167 | * Keys can be between 1 and 256 bytes long. |
156 | * |
168 | * |
- | 169 | * @access public |
|
157 | * @param string $key |
170 | * @param string $key |
158 | */ |
171 | */ |
159 | public function setKey($key) |
172 | public function setKey($key) |
160 | { |
173 | { |
161 | $length = strlen($key); |
174 | $length = strlen($key); |
Line 169... | Line 182... | ||
169 | /** |
182 | /** |
170 | * Encrypts a message. |
183 | * Encrypts a message. |
171 | * |
184 | * |
172 | * @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() |
185 | * @see \phpseclib3\Crypt\Common\SymmetricKey::decrypt() |
173 | * @see self::crypt() |
186 | * @see self::crypt() |
- | 187 | * @access public |
|
174 | * @param string $plaintext |
188 | * @param string $plaintext |
175 | * @return string $ciphertext |
189 | * @return string $ciphertext |
176 | */ |
190 | */ |
177 | public function encrypt($plaintext) |
191 | public function encrypt($plaintext) |
178 | { |
192 | { |
Line 188... | Line 202... | ||
188 | * $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)). |
202 | * $this->decrypt($this->encrypt($plaintext)) == $this->encrypt($this->encrypt($plaintext)). |
189 | * At least if the continuous buffer is disabled. |
203 | * At least if the continuous buffer is disabled. |
190 | * |
204 | * |
191 | * @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() |
205 | * @see \phpseclib3\Crypt\Common\SymmetricKey::encrypt() |
192 | * @see self::crypt() |
206 | * @see self::crypt() |
- | 207 | * @access public |
|
193 | * @param string $ciphertext |
208 | * @param string $ciphertext |
194 | * @return string $plaintext |
209 | * @return string $plaintext |
195 | */ |
210 | */ |
196 | public function decrypt($ciphertext) |
211 | public function decrypt($ciphertext) |
197 | { |
212 | { |
Line 202... | Line 217... | ||
202 | } |
217 | } |
203 | 218 | ||
204 | /** |
219 | /** |
205 | * Encrypts a block |
220 | * Encrypts a block |
206 | * |
221 | * |
- | 222 | * @access private |
|
207 | * @param string $in |
223 | * @param string $in |
208 | */ |
224 | */ |
209 | protected function encryptBlock($in) |
225 | protected function encryptBlock($in) |
210 | { |
226 | { |
211 | // RC4 does not utilize this method |
227 | // RC4 does not utilize this method |
212 | } |
228 | } |
213 | 229 | ||
214 | /** |
230 | /** |
215 | * Decrypts a block |
231 | * Decrypts a block |
216 | * |
232 | * |
- | 233 | * @access private |
|
217 | * @param string $in |
234 | * @param string $in |
218 | */ |
235 | */ |
219 | protected function decryptBlock($in) |
236 | protected function decryptBlock($in) |
220 | { |
237 | { |
221 | // RC4 does not utilize this method |
238 | // RC4 does not utilize this method |
Line 223... | Line 240... | ||
223 | 240 | ||
224 | /** |
241 | /** |
225 | * Setup the key (expansion) |
242 | * Setup the key (expansion) |
226 | * |
243 | * |
227 | * @see \phpseclib3\Crypt\Common\SymmetricKey::_setupKey() |
244 | * @see \phpseclib3\Crypt\Common\SymmetricKey::_setupKey() |
- | 245 | * @access private |
|
228 | */ |
246 | */ |
229 | protected function setupKey() |
247 | protected function setupKey() |
230 | { |
248 | { |
231 | $key = $this->key; |
249 | $key = $this->key; |
232 | $keyLength = strlen($key); |
250 | $keyLength = strlen($key); |
Line 250... | Line 268... | ||
250 | /** |
268 | /** |
251 | * Encrypts or decrypts a message. |
269 | * Encrypts or decrypts a message. |
252 | * |
270 | * |
253 | * @see self::encrypt() |
271 | * @see self::encrypt() |
254 | * @see self::decrypt() |
272 | * @see self::decrypt() |
- | 273 | * @access private |
|
255 | * @param string $text |
274 | * @param string $text |
256 | * @param int $mode |
275 | * @param int $mode |
257 | * @return string $text |
276 | * @return string $text |
258 | */ |
277 | */ |
259 | private function crypt($text, $mode) |
278 | private function crypt($text, $mode) |