151 switch (strlen($this->key)) {
153 $this->cipher_name_openssl =
'rc4-40';
156 $this->cipher_name_openssl =
'rc4-64';
159 $this->cipher_name_openssl =
'rc4';
166 return parent::isValidEngine(
$engine);
203 $this->key_length = 1;
204 } elseif ($length > 2048) {
205 $this->key_length = 248;
207 $this->key_length = $length >> 3;
210 parent::setKeyLength($length);
225 return parent::encrypt($plaintext);
227 return $this->
_crypt($plaintext, self::ENCRYPT);
245 return parent::decrypt($ciphertext);
247 return $this->
_crypt($ciphertext, self::DECRYPT);
281 $keyLength = strlen($key);
282 $keyStream = range(0, 255);
284 for (
$i = 0;
$i < 256;
$i++) {
285 $j = ($j + $keyStream[
$i] + ord($key[
$i % $keyLength])) & 255;
286 $temp = $keyStream[
$i];
287 $keyStream[
$i] = $keyStream[$j];
288 $keyStream[$j] = $temp;
291 $this->stream = array();
292 $this->stream[self::DECRYPT] = $this->stream[self::ENCRYPT] = array(
311 if ($this->changed) {
313 $this->changed =
false;
316 $stream = &$this->stream[
$mode];
317 if ($this->continuousBuffer) {
320 $keyStream = &$stream[2];
324 $keyStream = $stream[2];
327 $len = strlen(
$text);
328 for ($k = 0; $k < $len; ++$k) {
330 $ksi = $keyStream[
$i];
331 $j = ($j + $ksi) & 255;
332 $ksj = $keyStream[$j];
334 $keyStream[
$i] = $ksj;
335 $keyStream[$j] = $ksi;
336 $text[$k] =
$text[$k] ^ chr($keyStream[($ksj + $ksi) & 255]);
encrypt($plaintext)
Encrypts a message.
__construct()
Default Constructor.
decrypt($ciphertext)
Decrypts a message.
const ENGINE_OPENSSL
Base value for the mcrypt implementation $engine switch.
_encryptBlock($in)
Encrypts a block.
setKeyLength($length)
Sets the key length.
isValidEngine($engine)
Test for engine validity.
Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic...
_setup()
Setup the self::ENGINE_INTERNAL $engine.
const MODE_STREAM
Encrypt / decrypt using streaming mode.
_decryptBlock($in)
Decrypts a block.
setIV($iv)
Dummy function.
if(php_sapi_name() !='cli') $in
Pure-PHP implementation of RC4.
Base Class for all * cipher classes.
_setupKey()
Setup the key (expansion)
const ENGINE_INTERNAL
#+ private
_crypt($text, $mode)
Encrypts or decrypts a message.