コード例 #1
0
ファイル: jCrypt.class.php プロジェクト: havefnubb/havefnubb
 public static function encrypt($string, $key = '')
 {
     $encrypted = null;
     if (function_exists("mcrypt_generic") && mcrypt_module_self_test(MCRYPT_WAKE)) {
         $encrypted = jCrypt::mcryptEncrypt($string, $key);
     } else {
         $encrypted = jCrypt::simpleCrypt($string, $key);
     }
     return base64_encode($encrypted);
 }
コード例 #2
0
 /**
  * Encrypt a string with a specific key
  * @param string $string the string to encrypt
  * @param string $key the key used to encrypt
  * @return string encrypted string
  */
 public static function encrypt($string, $key)
 {
     $encrypted = null;
     // Check if mcrypt is installed, and if WAKE algo exists
     if (function_exists("mcrypt_generic") && mcrypt_module_self_test(MCRYPT_WAKE)) {
         $encrypted = jCrypt::mcryptEncrypt($string, $key);
     } else {
         $encrypted = jCrypt::simpleCrypt($string, $key);
     }
     return base64_encode($encrypted);
 }
コード例 #3
0
ファイル: main_funcs.php プロジェクト: emanuelwiesner/arcanum
function check_environment()
{
    global $config;
    //check mcrypt
    if (!function_exists('mcrypt_encrypt')) {
        throw new arcException('PHPs mcrypt library not available!');
    }
    //check ciphers
    foreach ($config['used_mcrypt_ciphers'] as $cipher => $mode) {
        if (!mcrypt_module_self_test($cipher)) {
            throw new arcException('Trying to use cipher [' . $cipher . '], but self-test failed!');
        }
    }
    //check paths
    if (!is_dir($config['tmppath'])) {
        @mkdir($config['tmppath']);
        chmod($config['tmppath'], 0700);
    }
    if (!is_writable($config['tmppath'])) {
        throw new arcException("tmppath " . $config['tmppath'] . " is not writable!");
    }
    if (!is_dir($config['cache_path'])) {
        @mkdir($config['cache_path']);
        chmod($config['cache_path'], 0700);
    }
    if (!is_writable($config['cache_path'])) {
        throw new arcException("cache_path " . $config['cache_path'] . " is not writable!");
    }
    $virusscanner = explode(' ', $config['virusscanner']);
    if (!is_executable($virusscanner[0]) && $config['enablevirusscan'] === TRUE) {
        throw new arcException("Filescanner [" . $config['virusscanner'] . "] not executable");
    }
    if (!is_dir($config['js_lang_realpath'])) {
        @mkdir($config['js_lang_realpath']);
        //dont throw any arcException, arcanum may work anyway
    }
}
コード例 #4
0
ファイル: Mcrypt.php プロジェクト: blazeriaz/youguess
 /**
  * Sets new encryption options
  *
  * @param  string|array $options Encryption options
  * @return Zend_Filter_File_Encryption
  */
 public function setEncryption($options)
 {
     if (is_string($options)) {
         $options = array('key' => $options);
     }
     if (!is_array($options)) {
         #require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception('Invalid options argument provided to filter');
     }
     $options = $options + $this->getEncryption();
     $algorithms = mcrypt_list_algorithms($options['algorithm_directory']);
     if (!in_array($options['algorithm'], $algorithms)) {
         #require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception("The algorithm '{$options['algorithm']}' is not supported");
     }
     $modes = mcrypt_list_modes($options['mode_directory']);
     if (!in_array($options['mode'], $modes)) {
         #require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception("The mode '{$options['mode']}' is not supported");
     }
     if (!mcrypt_module_self_test($options['algorithm'], $options['algorithm_directory'])) {
         #require_once 'Zend/Filter/Exception.php';
         throw new Zend_Filter_Exception('The given algorithm can not be used due an internal mcrypt problem');
     }
     if (!isset($options['vector'])) {
         $options['vector'] = null;
     }
     $this->_encryption = $options;
     $this->setVector($options['vector']);
     return $this;
 }
コード例 #5
0
ファイル: xcrud.php プロジェクト: jccarrizo/git-hub-proyect
 public function decrypt($text, $iv)
 {
     if (!Xcrud_config::$alt_encription_key) {
         self::error('Please, set <strong>$alt_encription_key</strong> parameter in configuration file');
     }
     if (!is_callable('mcrypt_module_open')) {
         self::error('<strong>mcrypt_module</strong> not found');
     }
     if (defined('MCRYPT_TWOFISH') && mcrypt_module_self_test(MCRYPT_TWOFISH)) {
         $algoritm = MCRYPT_TWOFISH;
     } elseif (defined('MCRYPT_RIJNDAEL_256') && mcrypt_module_self_test(MCRYPT_RIJNDAEL_256)) {
         $algoritm = MCRYPT_RIJNDAEL_256;
     } elseif (defined('MCRYPT_SERPENT') && mcrypt_module_self_test(MCRYPT_SERPENT)) {
         $algoritm = MCRYPT_SERPENT;
     } elseif (defined('MCRYPT_BLOWFISH') && mcrypt_module_self_test(MCRYPT_BLOWFISH)) {
         $algoritm = MCRYPT_BLOWFISH;
     } else {
         self::error('MCRYPT - Supported algorytm not found');
     }
     $td = mcrypt_module_open($algoritm, '', MCRYPT_MODE_CFB, '');
     $ks = mcrypt_enc_get_key_size($td);
     $key = substr(Xcrud_config::$alt_encription_key, 0, $ks);
     mcrypt_generic_init($td, $key, base64_decode($iv));
     $decrypted = mdecrypt_generic($td, base64_decode($text));
     mcrypt_generic_deinit($td);
     mcrypt_module_close($td);
     $obj = json_decode($decrypted, true);
     return $obj;
 }
コード例 #6
0
ファイル: mcrypt.php プロジェクト: phpseclib/mcrypt_compat
 function mcrypt_module_self_test($algorithm, $lib_dir = '')
 {
     return mcrypt_module_self_test($algorithm, $lib_dir);
 }
コード例 #7
0
ファイル: Crypt.class.php プロジェクト: EWegrzynowski/sysPass
 /**
  * Comprobar si el módulo de encriptación está disponible.
  *
  * @return bool
  */
 public static function checkCryptModule()
 {
     return mcrypt_module_self_test(MCRYPT_RIJNDAEL_256);
 }
コード例 #8
0
ファイル: ext_mcrypt.php プロジェクト: badlamer/hhvm
mcrypt_generic_init($td, $key, $iv);
$decrypted = mdecrypt_generic($td, $encrypted);
mcrypt_generic_end($td);
mcrypt_module_close($td);
VS($decrypted, "This is very important data");
VERIFY(in_array("blowfish", mcrypt_list_algorithms()));
VERIFY(in_array("cbc", mcrypt_list_modes()));
VS(mcrypt_module_get_algo_block_size("blowfish"), 8);
VS(mcrypt_module_get_algo_key_size("blowfish"), 56);
VS(mcrypt_module_get_supported_key_sizes("blowfish"), array());
VS(mcrypt_module_get_supported_key_sizes("twofish"), array(16, 24, 32));
VS(mcrypt_module_is_block_algorithm_mode("cbc"), true);
VS(mcrypt_module_is_block_algorithm("blowfish"), true);
VS(mcrypt_module_is_block_mode("cbc"), true);
VS(mcrypt_module_self_test(MCRYPT_RIJNDAEL_128), true);
VS(mcrypt_module_self_test("bogus"), false);
$text = "boggles the inivisble monkey will rule the world";
$key = "very secret key";
$iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$enc = mcrypt_encrypt(MCRYPT_XTEA, $key, $text, MCRYPT_MODE_ECB, $iv);
VS(bin2hex($enc), "f522c62002fa16129c8576bcddc6dd0f7ea81991103ba42962d94c8bfff3ee660d53b187d7e989540abf5a729c2f7baf");
$crypttext = mcrypt_decrypt(MCRYPT_XTEA, $key, $enc, MCRYPT_MODE_ECB, $iv);
VS($crypttext, $text);
//////////////////////////////////////////////////////////////////////
$key = "123456789012345678901234567890123456789012345678901234567890";
$CC = "4007000000027";
$encrypted = mcrypt_cbc(MCRYPT_RIJNDAEL_128, substr($key, 0, 32), $CC, MCRYPT_ENCRYPT, substr($key, 32, 16));
$decrypted = mcrypt_cbc(MCRYPT_RIJNDAEL_128, substr($key, 0, 32), $encrypted, MCRYPT_DECRYPT, substr($key, 32, 16));
VERIFY($encrypted !== $decrypted);
VS(trim((string) $decrypted), $CC);
コード例 #9
0
<?php

var_dump(mcrypt_module_self_test(MCRYPT_RIJNDAEL_128));
var_dump(mcrypt_module_self_test(MCRYPT_RC2));
var_dump(mcrypt_module_self_test(''));
コード例 #10
0
ファイル: Crypt.php プロジェクト: robtuley/knotwerk
 /**
  * Run mcrypt module self-test.
  */
 function testSelfModuleMcrypt()
 {
     $this->assertTrue(mcrypt_module_self_test(MCRYPT_RIJNDAEL_256));
     $this->assertTrue(mcrypt_module_self_test(MCRYPT_BLOWFISH));
 }
コード例 #11
0
 /**
  * Performs an internal self-test on the specified mcrypt algorithm and
  * returns either boolean true/false depending on if the self-test passed
  * or failed.
  *
  * @param  string  $cipher_type
  * @return boolean
  */
 public function algoSelfTest($cipher_type = MCRYPT_TRIPLEDES)
 {
     return mcrypt_module_self_test($cipher_type);
 }