[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/Cipher/ -> rc4.php (source)

   1  <?php
   2  /**
   3   * The Cipher_rc4:: class implements the Cipher interface encryption data
   4   * using the RC4 encryption algorthim. This class uses the PEAR Crypt_RC4
   5   * class to do the encryption.
   6   *
   7   * $Horde: framework/Cipher/Cipher/rc4.php,v 1.4.12.7 2006/01/01 21:28:10 jan Exp $
   8   *
   9   * Copyright 2002-2006 Mike Cochrane <mike@graftonhall.co.nz>
  10   *
  11   * See the enclosed file COPYING for license information (LGPL). If you
  12   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  13   *
  14   * @author  Mike Cochrane <mike@graftonhall.co.nz>
  15   * @since   Horde 2.2
  16   * @package Horde_Cipher
  17   */
  18  class Horde_Cipher_rc4 extends Horde_Cipher {
  19  
  20      /**
  21       * Pointer to a PEAR Crypt_rc4 object
  22       *
  23       * @var array
  24       */
  25      var $_cipher = array();
  26  
  27      /**
  28       * Constructor
  29       */
  30      function Horde_Cipher_rc4($params = null)
  31      {
  32          require_once 'Crypt/Rc4.php';
  33          $this->_cipher = &new Crypt_Rc4();
  34      }
  35  
  36      /**
  37       * Set the key to be used for en/decryption.
  38       *
  39       * @param string $key  The key to use.
  40       */
  41      function setKey($key)
  42      {
  43          $this->_cipher->key($key);
  44      }
  45  
  46      /**
  47       * Return the size of the blocks that this cipher needs.
  48       *
  49       * @return integer  The number of characters per block.
  50       */
  51      function getBlockSize()
  52      {
  53          return 8;
  54      }
  55  
  56      /**
  57       * Encrypt a block of data.
  58       *
  59       * @param string $block  The data to encrypt.
  60       * @param string $key    The key to use.
  61       *
  62       * @return string  The encrypted output.
  63       */
  64      function encryptBlock($block, $key = null)
  65      {
  66          if (!is_null($key)) {
  67              $this->setKey($key);
  68          }
  69  
  70          // Make a copy of the cipher as it destroys itself during a crypt
  71          $cipher = $this->_cipher;
  72          $cipher->crypt($block);
  73  
  74          return $block;
  75      }
  76  
  77      /**
  78       * Decrypt a block of data.
  79       *
  80       * @param string $block  The data to decrypt.
  81       * @param string $key    The key to use.
  82       *
  83       * @return string  The decrypted output.
  84       */
  85      function decryptBlock($block, $key = null)
  86      {
  87          if (!is_null($key)) {
  88              $this->setKey($key);
  89          }
  90  
  91          // Make a copy of the cipher as it destroys itself during a
  92          // crypt.
  93          $cipher = $this->_cipher;
  94          $cipher->decrypt($block);
  95  
  96          return $block;
  97      }
  98  
  99  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7