Example #1
0
<?php

$key = "0123456789012345";
$secret = "PHP Testfest 2008";
$cipher = MCRYPT_RIJNDAEL_128;
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher, MCRYPT_MODE_ECB), MCRYPT_RAND);
$enc_data = mcrypt_ofb($cipher, $key, $secret, MCRYPT_ENCRYPT, $iv);
// we have to trim as AES rounds the blocks and decrypt doesnt detect that
echo trim(mcrypt_ofb($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv)) . "\n";
// a warning must be issued if we don't use a IV on a AES cipher, that usually requires an IV
mcrypt_ofb($cipher, $key, $enc_data, MCRYPT_DECRYPT, $iv);
Example #2
0
 /**
  * sessDecrypt - Decrypts encrypted text created by the sessEncrypt member.
  * It needs to be passed the same Initialization Vector (IV) used in the
  * encryption process. When you have a few/many fields to decrypt in one
  * script cycle, choose to keep the mcrypt module open to speed up
  * decryption (only for libmcrypt >= 2.4.x). A correctly decrypted field
  * will be returned as a string, so if you're expecting/wanting an integer
  * then you have to type cast or use intval() function.
  *
  * @param  string $_enc Pass the encrypted text you would like to decrypt.
  * @param  string $_IV Pass the same IV used in the encryption phase.
  * @param  bool   $_keep_open TRUE to keep mcrypt module open, FALSE close.
  * @return mixed  Returns the original plain text or FALSE on error.
  * @access public
  */
 function sessDecrypt($_enc, $_IV, $_keep_open = FALSE)
 {
     static $_open_already = FALSE;
     // Open encrypt flag For ver >= 2.4.x
     static $_module = NULL;
     if (!is_bool($_keep_open)) {
         $_keep_open = FALSE;
     }
     if (is_numeric($_IV) && strlen($_IV) > 0 && strlen($_IV) < 4 && intval($_IV) > 0 && intval($_IV) < 501) {
         $_text = $this->sessDecode($_enc, intval($_IV));
     } else {
         if ($this->_MCRYPT && !empty($this->_ENC_ALGO) && !empty($this->_ENC_MODE)) {
             $_IV = @base64_decode($_IV);
             $_enc = @base64_decode($_enc);
             if ($this->_MCRYPT_LATEST) {
                 // For >= 2.4.x
                 if (!$_open_already) {
                     $_module = @mcrypt_module_open($this->_ENC_ALGO, '', $this->_ENC_MODE, '');
                     if (FALSE === $_module) {
                         // Could not open encryption module for decryption
                         $this->_setErrMsg('DEC_OPEN_FAIL', NULL, $this->_ENC_ALGO, $this->_ENC_MODE);
                         $this->_handleErrors();
                         return FALSE;
                     }
                     $_open_already = TRUE;
                 }
                 $_key = substr($this->_ENC_KEY_HASHED, 0, @mcrypt_enc_get_key_size($_module));
                 $_result = @mcrypt_generic_init($_module, $_key, $_IV);
                 if ($_result < 0) {
                     switch ($_result) {
                         case -3:
                             // Key length for decryption is incorrect
                             $this->_setErrMsg('DEC_KEY_LEN', NULL, $this->_ENC_ALGO, $this->_ENC_MODE, strlen($_key));
                         case -4:
                             // There were memory allocation problems - decrypt
                             $this->_setErrMsg('DEC_MEMORY', NULL, $this->_ENC_ALGO, $this->_ENC_MODE);
                         default:
                             // There were unknown errors while trying to decrypt
                             $this->_setErrMsg('DEC_UNKNOWN', NULL, $this->_ENC_ALGO, $this->_ENC_MODE);
                     }
                     $this->_handleErrors();
                     return FALSE;
                 }
                 // trim is especially needed in Cipher Block Chaining (CBC) mode
                 $_text = trim(@mdecrypt_generic($_module, $_enc));
                 if (!$_keep_open) {
                     @mcrypt_generic_deinit($_module);
                     @mcrypt_module_close($_module);
                     $_open_already = FALSE;
                     $_module = NULL;
                 }
             } else {
                 // For 2.2.x
                 $_key = substr($this->_ENC_KEY_HASHED, 0, @mcrypt_get_key_size($this->_ENC_ALGO));
                 switch ($this->_ENC_MODE) {
                     case MCRYPT_MODE_ECB:
                         $_text = @mcrypt_ecb($this->_ENC_ALGO, $_key, $_enc, MCRYPT_DECRYPT);
                         break;
                     case MCRYPT_MODE_CFB:
                         $_text = @mcrypt_cfb($this->_ENC_ALGO, $_key, $_enc, MCRYPT_DECRYPT, $_IV);
                         break;
                     case MCRYPT_MODE_OFB:
                         $_text = @mcrypt_ofb($this->_ENC_ALGO, $_key, $_enc, MCRYPT_DECRYPT, $_IV);
                         break;
                     default:
                         $_text = @mcrypt_cbc($this->_ENC_ALGO, $_key, $_enc, MCRYPT_DECRYPT, $_IV);
                 }
                 $_text = trim($_text);
                 // Especially needed for CBC mode
             }
         } else {
             $_text = FALSE;
         }
     }
     return $_text;
 }
Example #3
0
import_request_variables();
mcrypt_generic_end();
mysql_db_query();
mysql_escape_string();
mysql_list_dbs();
mysqli_bind_param();
mysqli_bind_result();
mysqli_client_encoding();
mysqli_fetch();
mysqli_param_count();
mysqli_get_metadata();
mysqli_send_long_data();
magic_quotes_runtime();
session_register();
session_unregister();
session_is_registered();
set_magic_quotes_runtime();
set_socket_blocking();
split();
spliti();
sql_regcase();
php_logo_guid();
php_egg_logo_guid();
php_real_logo_guid();
zend_logo_guid();
datefmt_set_timezone_id();
mcrypt_ecb();
mcrypt_cbc();
mcrypt_cfb();
mcrypt_ofb();
Example #4
0
$encrypted = mcrypt_cfb(MCRYPT_RIJNDAEL_128, substr($key, 0, 32), $CC, MCRYPT_ENCRYPT, substr($key, 32, 16));
$decrypted = mcrypt_cfb(MCRYPT_RIJNDAEL_128, substr($key, 0, 32), $encrypted, MCRYPT_DECRYPT, substr($key, 32, 16));
VERIFY($encrypted !== $decrypted);
VS(trim((string) $decrypted), $CC);
//////////////////////////////////////////////////////////////////////
$key = "123456789012345678901234567890123456789012345678901234567890";
$CC = "4007000000027";
$encrypted = mcrypt_ecb(MCRYPT_RIJNDAEL_128, substr($key, 0, 32), $CC, MCRYPT_ENCRYPT, substr($key, 32, 16));
$decrypted = mcrypt_ecb(MCRYPT_RIJNDAEL_128, substr($key, 0, 32), $encrypted, MCRYPT_DECRYPT, substr($key, 32, 16));
VERIFY($encrypted !== $decrypted);
VS(trim((string) $decrypted), $CC);
//////////////////////////////////////////////////////////////////////
$key = "123456789012345678901234567890123456789012345678901234567890";
$CC = "4007000000027";
$encrypted = mcrypt_ofb(MCRYPT_RIJNDAEL_128, substr($key, 0, 32), $CC, MCRYPT_ENCRYPT, substr($key, 32, 16));
$decrypted = mcrypt_ofb(MCRYPT_RIJNDAEL_128, substr($key, 0, 32), $encrypted, MCRYPT_DECRYPT, substr($key, 32, 16));
VERIFY($encrypted !== $decrypted);
VS($decrypted, $CC);
//////////////////////////////////////////////////////////////////////
VS(mcrypt_get_block_size("tripledes", "ecb"), 8);
VS(mcrypt_get_cipher_name(MCRYPT_TRIPLEDES), "3DES");
VS(mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB), 16);
VS(mcrypt_get_iv_size("des", "ecb"), 8);
VS(mcrypt_get_key_size("tripledes", "ecb"), 24);
$td = mcrypt_module_open("cast-256", "", "cfb", "");
VS(mcrypt_enc_get_algorithms_name($td), "CAST-256");
$td = mcrypt_module_open("tripledes", "", "ecb", "");
VS(mcrypt_enc_get_block_size($td), 8);
$td = mcrypt_module_open("cast-256", "", "cfb", "");
VS(mcrypt_enc_get_iv_size($td), 16);
$td = mcrypt_module_open("tripledes", "", "ecb", "");