[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Horde_Cipher:: class provides a common abstracted interface to 4 * various Ciphers for encryption of arbitrary length pieces of data. 5 * 6 * Copyright 2002-2006 Mike Cochrane <mike@graftonhall.co.nz> 7 * 8 * See the enclosed file COPYING for license information (LGPL). If you 9 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 10 * 11 * $Horde: framework/Cipher/Cipher.php,v 1.16.12.8 2006/01/01 21:28:10 jan Exp $ 12 * 13 * @author Mike Cochrane <mike@graftonhall.co.nz> 14 * @since Horde 2.2 15 * @package Horde_Cipher 16 */ 17 class Horde_Cipher { 18 19 /** 20 * The block mode for the cipher chaining 21 * 22 * @var string 23 */ 24 var $_blockMode = 'CBC'; 25 26 /** 27 * The initialization vector 28 * 29 * @var string 30 */ 31 var $_iv = null; 32 33 /** 34 * Set the block mode for cipher chaining. 35 * 36 * @param string $blockMode The new blockmode. 37 */ 38 function setBlockMode($blockMode) 39 { 40 $this->_blockMode = $blockMode; 41 } 42 43 /** 44 * Set the IV. 45 * 46 * @param string $iv The new IV. 47 */ 48 function setIV($iv) 49 { 50 $this->_iv = $iv; 51 } 52 53 /** 54 * Encrypt a string. 55 * 56 * @param string $plaintext The data to encrypt. 57 * 58 * @return string The encrypted data. 59 */ 60 function encrypt($plaintext) 61 { 62 require_once dirname(__FILE__) . '/Cipher/BlockMode.php'; 63 $blockMode = &Horde_Cipher_BlockMode::factory($this->_blockMode); 64 if (!is_null($this->_iv)) { 65 $blockMode->setIV($this->_iv); 66 } 67 68 return $blockMode->encrypt($this, $plaintext); 69 } 70 71 /** 72 * Decrypt a string. 73 * 74 * @param string $ciphertext The data to decrypt. 75 * 76 * @return string The decrypted data. 77 */ 78 function decrypt($ciphertext) 79 { 80 require_once dirname(__FILE__) . '/Cipher/BlockMode.php'; 81 $blockMode = &Horde_Cipher_BlockMode::factory($this->_blockMode); 82 if (!is_null($this->_iv)) { 83 $blockMode->setIV($this->_iv); 84 } 85 86 return $blockMode->decrypt($this, $ciphertext); 87 } 88 89 /** 90 * Attempts to return a concrete Horde_Cipher instance. 91 * 92 * @param string $cipher The type of concrete Horde_Cipher subclass to 93 * return. 94 * @param array $params A hash containing any additional parameters a 95 * subclass might need. 96 * 97 * @return Horde_Cipher The newly created concrete Horde_Cipher instance, 98 * or PEAR_Error on error. 99 */ 100 function &factory($cipher, $params = null) 101 { 102 $driver = basename($cipher); 103 104 if (@file_exists(dirname(__FILE__) . '/Cipher/' . $cipher . '.php')) { 105 require_once dirname(__FILE__) . '/Cipher/' . $cipher . '.php'; 106 } 107 108 $class = 'Horde_Cipher_' . $cipher; 109 if (class_exists($class)) { 110 $cipher = &new $class($params); 111 } else { 112 $cipher = PEAR::raiseError('Class definition of ' . $class . ' not found.'); 113 } 114 115 return $cipher; 116 } 117 118 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |