public static function decodePassword($sPassword, $sSalt) { if (function_exists('mcrypt_encrypt') && function_exists('mcrypt_create_iv') && function_exists('mcrypt_get_iv_size') && defined('MCRYPT_RIJNDAEL_256') && defined('MCRYPT_MODE_ECB') && defined('MCRYPT_RAND')) { return @base64_decode(trim(@mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($sSalt), base64_decode(trim($sPassword)), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)))); } return @base64_decode(trim($sPassword)); }
/** * Loads encryption configuration and validates the data. * * @param array|string custom configuration or config group name * @throws Kohana_Exception */ public function __construct($config = FALSE) { if (!defined('MCRYPT_ENCRYPT')) { throw new Kohana_Exception('encrypt.requires_mcrypt'); } if (is_string($config)) { $name = $config; // Test the config group name if (($config = Kohana::config('encryption.' . $config)) === NULL) { throw new Kohana_Exception('encrypt.undefined_group', $name); } } if (is_array($config)) { // Append the default configuration options $config += Kohana::config('encryption.default'); } else { // Load the default group $config = Kohana::config('encryption.default'); } if (empty($config['key'])) { throw new Kohana_Exception('encrypt.no_encryption_key'); } // Find the max length of the key, based on cipher and mode $size = mcrypt_get_key_size($config['cipher'], $config['mode']); if (strlen($config['key']) > $size) { // Shorten the key to the maximum size $config['key'] = substr($config['key'], 0, $size); } // Find the initialization vector size $config['iv_size'] = mcrypt_get_iv_size($config['cipher'], $config['mode']); // Cache the config in the object $this->config = $config; Kohana::log('debug', 'Encrypt Library initialized'); }
public function __construct($_key = '', $_bit = 128, $_type = 'ecb', $_use_base64 = true) { // 加密字节 if (192 === $_bit) { $this->_bit = MCRYPT_RIJNDAEL_192; } elseif (128 === $_bit) { $this->_bit = MCRYPT_RIJNDAEL_128; } else { $this->_bit = MCRYPT_RIJNDAEL_256; } // 加密方法 if ('cfb' === $_type) { $this->_type = MCRYPT_MODE_CFB; } elseif ('cbc' === $_type) { $this->_type = MCRYPT_MODE_CBC; } elseif ('nofb' === $_type) { $this->_type = MCRYPT_MODE_NOFB; } elseif ('ofb' === $_type) { $this->_type = MCRYPT_MODE_OFB; } elseif ('stream' === $_type) { $this->_type = MCRYPT_MODE_STREAM; } else { $this->_type = MCRYPT_MODE_ECB; } // 密钥 if (!empty($_key)) { $this->_key = $_key; } // 是否使用base64 $this->_use_base64 = $_use_base64; $this->_iv_size = mcrypt_get_iv_size($this->_bit, $this->_type); $this->_iv = mcrypt_create_iv($this->_iv_size, MCRYPT_RAND); }
/** * Generate settings file */ public function generateSettingsFile($database_server, $database_login, $database_password, $database_name, $database_prefix, $database_engine) { // Check permissions for settings file if (file_exists(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE) && !is_writable(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE)) { $this->setError($this->language->l('%s file is not writable (check permissions)', self::SETTINGS_FILE)); return false; } elseif (!file_exists(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE) && !is_writable(_PS_ROOT_DIR_ . '/' . dirname(self::SETTINGS_FILE))) { $this->setError($this->language->l('%s folder is not writable (check permissions)', dirname(self::SETTINGS_FILE))); return false; } // Generate settings content and write file $settings_constants = array('_DB_SERVER_' => $database_server, '_DB_NAME_' => $database_name, '_DB_USER_' => $database_login, '_DB_PASSWD_' => $database_password, '_DB_PREFIX_' => $database_prefix, '_MYSQL_ENGINE_' => $database_engine, '_PS_CACHING_SYSTEM_' => 'CacheMemcache', '_PS_CACHE_ENABLED_' => '0', '_MEDIA_SERVER_1_' => '', '_MEDIA_SERVER_2_' => '', '_MEDIA_SERVER_3_' => '', '_COOKIE_KEY_' => Tools::passwdGen(56), '_COOKIE_IV_' => Tools::passwdGen(8), '_PS_CREATION_DATE_' => date('Y-m-d'), '_PS_VERSION_' => _PS_INSTALL_VERSION_); // If mcrypt is activated, add Rijndael 128 configuration if (function_exists('mcrypt_encrypt')) { $settings_constants['_RIJNDAEL_KEY_'] = Tools::passwdGen(mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB)); $settings_constants['_RIJNDAEL_IV_'] = base64_encode(mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND)); } $settings_content = "<?php\n"; foreach ($settings_constants as $constant => $value) { $settings_content .= "define('{$constant}', '" . str_replace('\'', '\\\'', $value) . "');\n"; } if (!file_put_contents(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE, $settings_content)) { $this->setError($this->language->l('Cannot write settings file')); return false; } return true; }
private static function _decrypt($value, $key) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($value), MCRYPT_MODE_ECB, $iv); return trim($decrypttext); }
function __construct($cipher) { $this->cipher = $cipher; $this->key_size = mcrypt_module_get_algo_key_size($cipher); $this->block_size = mcrypt_module_get_algo_block_size($cipher); $this->iv = str_repeat("", mcrypt_get_iv_size($cipher, 'ncfb')); }
public static function decrypted($encrypted, $key) { $data = base64_decode($encrypted); $iv = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, hash('sha256', $key, true), substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)), MCRYPT_MODE_CBC, $iv), ""); return $decrypted; }
/** * @param string $cypher * @param string $mode * @param int $ivMode */ public function __construct($cypher = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_ECB, $ivMode = MCRYPT_RAND) { $this->cypher = $cypher; $this->mode = $mode; $ivSize = mcrypt_get_iv_size($cypher, $mode); $this->iv = mcrypt_create_iv($ivSize, $ivMode); }
/** * 解密函数 * @param string $decrypt * @param string $key * @return string */ public function decrypt($decrypt, $key = '') { $decoded = base64_decode($decrypt); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND); $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), $decoded, MCRYPT_MODE_ECB, $iv); return $decrypted; }
/** * see crypt::decrypt(); */ public function decrypt($data) { if ($this->base64) { $decoded = base64_decode($data); } else { $decoded = $data; } // extract values out of data $iv_size = mcrypt_get_iv_size($this->cipher, $this->mode); $iv = mb_substr($decoded, 0, $iv_size, 'latin1'); $hash_size = mb_strlen($this->hash(1), 'latin1'); $hash = mb_substr($decoded, $iv_size, $hash_size, 'latin1'); $cipher = mb_substr($decoded, $iv_size + $hash_size, mb_strlen($decoded, 'latin1'), 'latin1'); // comparing ciper with hash if ($this->hash($cipher) != $hash) { return false; } // decrypting $decrypted = mcrypt_decrypt($this->cipher, $this->key, $cipher, $this->mode, $iv); if ($decrypted !== false) { return rtrim($decrypted, ""); } else { return false; } }
public function __construct($key, $mode = MCRYPT_MODE_ECB, $iv = NULL, $bit = AESMcrypt::BIT_128) { // check mcrypt module if (!extension_loaded("mcrypt")) { trigger_error('AESMcrypt class need mcrypt module'); return; } switch ($bit) { case AESMcrypt::BIT_192: $this->_cipher = MCRYPT_RIJNDAEL_192; break; case AESMcrypt::BIT_256: $this->_cipher = MCRYPT_RIJNDAEL_256; break; default: $this->_cipher = MCRYPT_RIJNDAEL_128; break; } $modes = array(MCRYPT_MODE_ECB, MCRYPT_MODE_CBC, MCRYPT_MODE_CFB, MCRYPT_MODE_OFB, MCRYPT_MODE_NOFB); if (in_array($mode, $modes)) { $this->_mode = $mode; } else { $this->_mode = MCRYPT_MODE_ECB; } $this->_key = $key; $this->_iv = $iv; // check iv size, ecb模式不需要iv if ($this->_mode != MCRYPT_MODE_ECB) { $needIVSize = mcrypt_get_iv_size($this->_cipher, $this->_mode); if (strlen($iv) != $needIVSize) { trigger_error("IV size wrong, need a string of length {$needIVSize}"); return; } } }
function aesdecrypt($s, $key) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $iv = substr($s, 0, $iv_size); $crypto = substr($s, $iv_size); return @mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $crypto, MCRYPT_MODE_CBC, $iv); }
function decrypt($text, $salt) { if (!$text) { return false; } return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND))); }
public function __construct($encryption_key) { $this->prefix = version_compare(PHP_VERSION, '5.3.7') < 0 ? '$2a' : '$2y'; $this->encryptionHash = str_split(hash('sha256', $encryption_key)); // SHA-256 hash array $this->iv_size = mcrypt_get_iv_size($this->cipher, $this->mcryptMode); }
function do_encrypt($data) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $encrypt = getEncryptionKey(32); return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $encrypt, $data, MCRYPT_MODE_CBC, $iv)); }
function encryptCookie($value) { // serialize array values if (!$value) { return false; } if (is_array($value)) { $value = serialize($value); } // generate an SHA-256 HMAC hash where data = session ID and key = defined constant $key = hash_hmac('sha256', session_id(), ENCRYPTION_KEY_HMAC); if (strlen($key) > 24) { $key = substr($key, 0, 24); } // generate random value for IV $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); // encrypt the data with the key and IV using AES-256 $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_CBC, $iv); // generate an SHA-256 HMAC hash where data = encrypted text and key = defined constant $signature = hash_hmac('sha256', $crypttext, SIG_HMAC); $cookiedough = array(); $cookiedough['sig'] = $signature; $cookiedough['iv'] = $iv; $cookiedough['text'] = $crypttext; $final = serialize($cookiedough); return base64_encode($final); //encode for cookie }
static function decrypt($string, $date = 0) { if (empty($string)) { return ''; } $key = self::_getKey($date); if (!empty($key)) { $ciphertext_dec = base64_decode($string); if (function_exists('mcrypt_encrypt')) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); //vmdebug('decrypt $iv_size', $iv_size ,MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); // retrieves the IV, iv_size should be created using mcrypt_get_iv_size() $iv_dec = substr($ciphertext_dec, 0, $iv_size); //retrieves the cipher text (everything except the $iv_size in the front) $ciphertext_dec = substr($ciphertext_dec, $iv_size); vmdebug('decrypt $iv_dec', $iv_dec, $ciphertext_dec); if (empty($iv_dec) and empty($ciphertext_dec)) { vmdebug('Seems something not encrytped should be decrypted, return default ', $string); return $string; } else { $mcrypt_decrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec); return rtrim($mcrypt_decrypt, ""); } } else { return $ciphertext_dec; } } else { return $string; } }
function a2b_decrypt($text, $key) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size); $temp = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), $text, MCRYPT_MODE_ECB, $iv); return $temp; }
/** * Encrypt a string. * * @param string $str String to encrypt. * * @return string */ public function encrypt($str) { $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); $str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $str, MCRYPT_MODE_CBC, $iv); $str = $iv . $str; return base64_encode($str); }
/** * [hash description] * @param [type] $_i [description] * @return [type] [description] */ public static function hash($_i) { $size = mcrypt_get_iv_size(self::MCRYPT_SIZE, self::MCRYPT_MODE); $iv = mcrypt_create_iv($size, self::IV_SOURCE); $hash = self::pbkdf2(self::HASH_ALGORITHM, $_i, $iv, self::HASH_COUNT, self::OUTPUT_KEY_LEN); return $hash . $iv; }
public function SetEncryption() { $this->iv = mcrypt_create_iv(mcrypt_get_iv_size(self::ENCRYPTION_TYPE, self::ENCRYPTION_MODE), MCRYPT_DEV_URANDOM); $this->encryptionKey = strrev(Config::Init($this->app)->Get(\Puzzlout\Framework\Enums\AppSettingKeys::EncryptionKey)); $this->hashSalt = strrev(Config::Init($this->app)->Get(\Puzzlout\Framework\Enums\AppSettingKeys::PasswordSalt)); return $this; }
public static function decrypt($cipher, $key, $hmacSalt = null) { self::_checkKey($key, 'decrypt()'); if (empty($cipher)) { echo 'The data to decrypt cannot be empty.'; die; } if ($hmacSalt === null) { $hmacSalt = self::$salt; } $key = substr(hash('sha256', $key . $hmacSalt), 0, 32); # Generate the encryption and hmac key. # Split out hmac for comparison $macSize = 64; $hmac = substr($cipher, 0, $macSize); $cipher = substr($cipher, $macSize); $compareHmac = hash_hmac('sha256', $cipher, $key); if ($hmac !== $compareHmac) { return false; } $algorithm = MCRYPT_RIJNDAEL_128; # encryption algorithm $mode = MCRYPT_MODE_CBC; # encryption mode $ivSize = mcrypt_get_iv_size($algorithm, $mode); # Returns the size of the IV belonging to a specific cipher/mode combination $iv = substr($cipher, 0, $ivSize); $cipher = substr($cipher, $ivSize); $plain = mcrypt_decrypt($algorithm, $key, $cipher, $mode, $iv); return rtrim($plain, ""); }
function _output($value) { if (!isset($this->options) || !isset($this->options['meta_field']) || empty($this->options['meta_field'])) { // no value to show return ''; } global $post; $metaValue = get_post_meta($post->ID, $this->options['meta_field'], true); $value = $metaValue . ' <input type="hidden" name="cuztom[' . $this->name . ']" id="' . $this->id . '" value="' . $metaValue . '" />'; if (empty($metaValue)) { return ''; } if (isset($this->options) || isset($this->options['type']) && !empty($this->options['type'])) { // Deal with special types switch (strtolower($this->options['type'])) { case 'encrypted': $encKey = pack('H*', NM_ENCRYPTION_KEY); $ciphertext_dec = base64_decode($metaValue); $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $iv_dec = substr($ciphertext_dec, 0, $iv_size); $ciphertext_dec = substr($ciphertext_dec, $iv_size); $plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $encKey, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec); $value = $plaintext_dec; break; case 'currency': $value = '$' . number_format((double) $metaValue, 2); break; case 'payment_option': $value = get_term($metaValue, 'payment_options')->name; break; } } return $value; }
/** * Decrypt string * * NOTICE: the code in general, this method in particular, comes with absolutely no warranty. If security is * important for you, then use a purpose built package. https://github.com/defuse/php-encryption seems like * a good candidate. * @deprecated Do not trust a two-line decryption-method. * * @param string $string String to decrypt * @param string $key Key to encrypt/decrypt. * @return string Decrypted string */ public static function decrypt($string, $key) { $encryptedString = base64_decode($string); $initializationVector = substr($encryptedString, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB)); $decryptedString = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, hash("sha256", $key, true), substr($encryptedString, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB)), MCRYPT_MODE_CBC, $initializationVector), ""); return $decryptedString; }
function decrypt($encrypted_string, $encryption_key) { $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $encryption_key, base64_decode($encrypted_string), MCRYPT_MODE_ECB, $iv); return $decrypted_string; }
function decryptData($value, $filename, $name, $downloadBothMMStartTime) { //vale : encrypted data and filename : to decrypt file //AES 128-bit decryption $key = "Mary has one cat"; $crypttext = $value; $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $crypttext, MCRYPT_MODE_ECB, $iv); //writing to file filename.txt.decrypt $myfile = fopen("C:\\xampp\\htdocs\\BEPROJECT\\Html\\Decrypt/" . $name . ".decrypt", "w") or die("Unable to open file!"); fwrite($myfile, $decrypttext); $decrypt_file = $name . '.decrypt'; $storage = array(); $partialName = array(); $storage = explode("_", $name); //abc_mp3.txt $actualName = $storage[0]; //abc $tailName = $storage[1]; //mp3.txt $partialName = explode(".", $storage[1]); $extensionName = $partialName[0]; //mp3 $fullName = $actualName . "." . $extensionName; //abc.mp3 $fileNames = array('\\Multimedia/' . $fullName, '\\Decrypt/' . $decrypt_file); $zip_file_name = $actualName . '.zip'; $file_path = dirname(__FILE__); //echo "<br>".$file_path; zipFilesDownload($fileNames, $zip_file_name, $file_path, $downloadBothMMStartTime); fclose($myfile); }
public static function decode($decrypt, $key) { $decoded = base64_decode($decrypt); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB), MCRYPT_RAND); $decrypted = mcrypt_decrypt(MCRYPT_DES, $key, $decoded, MCRYPT_MODE_ECB, $iv); return $decrypted; }
/** * Loads encryption configuration and validates the data. * * @param array|string custom configuration or config group name * @throws Kohana_Exception */ public function __construct($config = FALSE) { if (!defined('MCRYPT_ENCRYPT')) { throw new Kohana_Exception('To use the Encrypt library, mcrypt must be enabled in your PHP installation'); } if (is_string($config)) { $name = $config; // Test the config group name if (($config = Kohana::config('encryption.' . $config)) === NULL) { throw new Kohana_Exception('The :name: group is not defined in your configuration.', array(':name:' => $name)); } } if (is_array($config)) { // Append the default configuration options $config += Kohana::config('encryption.default'); } else { // Load the default group $config = Kohana::config('encryption.default'); } if (empty($config['key'])) { throw new Kohana_Exception('To use the Encrypt library, you must set an encryption key in your config file'); } // Find the max length of the key, based on cipher and mode $size = mcrypt_get_key_size($config['cipher'], $config['mode']); if (strlen($config['key']) > $size) { // Shorten the key to the maximum size $config['key'] = substr($config['key'], 0, $size); } // Find the initialization vector size $config['iv_size'] = mcrypt_get_iv_size($config['cipher'], $config['mode']); // Cache the config in the object $this->config = $config; Kohana_Log::add('debug', 'Encrypt Library initialized'); }
function decrypt($text, $salt) { if (!function_exists('mcrypt_encrypt') || !function_exists('mcrypt_decrypt')) { return $text; } return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))); }
/** * Returns decrypted original string * @var $encrypted_string string the string to decrypt * @return string plain text */ function decrypt($encrypted_string) { $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $this->key, $encrypted_string, MCRYPT_MODE_ECB, $iv); return $decrypted_string; }