Documentation TYPO3 par Ameos

mcrypt.lib.php

00001 <?php
00002 
00003 /* $Id: mcrypt.lib.php,v 2.3 2005/02/07 16:46:02 rabus Exp $ */
00004 // vim: expandtab sw=4 ts=4 sts=4:
00005 
00010 // Store the initialization vector because it will be needed for
00011 // further decryption. I don't think necessary to have one iv
00012 // per server so I don't put the server number in the cookie name.
00013 
00014 if (!isset($_COOKIE['pma_mcrypt_iv'])) {
00015     srand((double) microtime() * 1000000);
00016     $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC), MCRYPT_RAND);
00017     setcookie('pma_mcrypt_iv',
00018         base64_encode($iv),
00019         time() + (60 * 60 * 24 * 30),
00020         $GLOBALS['cookie_path'], '',
00021         $GLOBALS['is_https']);
00022 } else {
00023     $iv = base64_decode($_COOKIE['pma_mcrypt_iv']);
00024 }
00025 
00038 function full_str_pad($input, $pad_length, $pad_string = '', $pad_type = 0) {
00039     $str = '';
00040     $length = $pad_length - strlen($input);
00041     if ($length > 0) { // str_repeat doesn't like negatives
00042         if ($pad_type == STR_PAD_RIGHT) { // STR_PAD_RIGHT == 1
00043             $str = $input.str_repeat($pad_string, $length);
00044         } elseif ($pad_type == STR_PAD_BOTH) { // STR_PAD_BOTH == 2
00045             $str = str_repeat($pad_string, floor($length/2));
00046             $str .= $input;
00047             $str .= str_repeat($pad_string, ceil($length/2));
00048         } else { // defaults to STR_PAD_LEFT == 0
00049             $str = str_repeat($pad_string, $length).$input;
00050         }
00051     } else { // if $length is negative or zero we don't need to do anything
00052         $str = $input;
00053     }
00054     return $str;
00055 }
00068 function PMA_blowfish_encrypt($data, $secret) {
00069     global $iv;
00070     // Seems we don't need the padding. Anyway if we need it,
00071     // we would have to replace 8 by the next 8-byte boundary.
00072     //$data = full_str_pad($data, 8, "\0", STR_PAD_RIGHT);
00073     return base64_encode(mcrypt_encrypt(MCRYPT_BLOWFISH, $secret, $data, MCRYPT_MODE_CBC, $iv));
00074 }
00075 
00088 function PMA_blowfish_decrypt($encdata, $secret) {
00089     global $iv;
00090     return trim(mcrypt_decrypt(MCRYPT_BLOWFISH, $secret, base64_decode($encdata), MCRYPT_MODE_CBC, $iv));
00091 }
00092 
00093 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6