[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Horde_Cipher_BlockMode_ecb:: This class implements the 4 * Horde_Cipher_BlockMode using the Electronic Code Book method of 5 * encrypting blocks of data. 6 * 7 * $Horde: framework/Cipher/Cipher/BlockMode/ecb.php,v 1.7.12.5 2006/01/01 21:28:11 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_BlockMode_ecb extends Horde_Cipher_BlockMode { 19 20 /** 21 * Encrypt a string. 22 * 23 * @param Horde_Cipher $cipher Cipher algorithm to use for 24 * encryption. 25 * @param string $plaintext The data to encrypt. 26 * 27 * @return The encrypted data. 28 */ 29 function encrypt(&$cipher, $plaintext) 30 { 31 $encrypted = ''; 32 $blocksize = $cipher->getBlockSize(); 33 34 $jMax = strlen($plaintext); 35 for ($j = 0; $j < $jMax; $j += $blocksize) { 36 $plain = substr($plaintext, $j, $blocksize); 37 38 if (strlen($plain) < $blocksize) { 39 // pad the block with \0's if it's not long enough 40 $plain = str_pad($plain, 8, "\0"); 41 } 42 43 $encrypted .= $cipher->encryptBlock($plain); 44 } 45 46 return $encrypted; 47 } 48 49 /** 50 * Decrypt a string. 51 * 52 * @param Horde_Cipher $cipher Cipher algorithm to use for 53 * decryption. 54 * @param string $ciphertext The data to decrypt. 55 * 56 * @return The decrypted data. 57 */ 58 function decrypt(&$cipher, $ciphertext) 59 { 60 $decrypted = ''; 61 $blocksize = $cipher->getBlockSize(); 62 63 $jMax = strlen($ciphertext); 64 for ($j = 0; $j < $jMax; $j += $blocksize) { 65 $plain = substr($ciphertext, $j, $blocksize); 66 $decrypted .= $cipher->decryptBlock($plain); 67 } 68 69 // Remove trailing \0's used to pad the last block. 70 while (substr($decrypted, -1, 1) == "\0") { 71 $decrypted = substr($decrypted, 0, -1); 72 } 73 74 return $decrypted; 75 } 76 77 }
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 |