/** * Constructor * * @param string $key Secret encryption key. * It's unsafe to store encryption key in memory, so no getter for key exists. * @param string $cipher Cipher algorithm (one of the MCRYPT_ciphername constants) * @param string $mode Mode of cipher algorithm (MCRYPT_MODE_modeabbr constants) * @param string|bool $initVector Initial vector to fill algorithm blocks. * TRUE generates a random initial vector. * FALSE fills initial vector with zero bytes to not use it. * @throws Magento_Exception */ public function __construct($key, $cipher = MCRYPT_BLOWFISH, $mode = MCRYPT_MODE_ECB, $initVector = false) { $this->_cipher = $cipher; $this->_mode = $mode; $this->_handle = mcrypt_module_open($cipher, '', $mode, ''); try { $maxKeySize = mcrypt_enc_get_key_size($this->_handle); if (strlen($key) > $maxKeySize) { throw new Magento_Exception('Key must not exceed ' . $maxKeySize . ' bytes.'); } $initVectorSize = mcrypt_enc_get_iv_size($this->_handle); if (true === $initVector) { /* Generate a random vector from human-readable characters */ $abc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $initVector = ''; for ($i = 0; $i < $initVectorSize; $i++) { $initVector .= $abc[rand(0, strlen($abc) - 1)]; } } else { if (false === $initVector) { /* Set vector to zero bytes to not use it */ $initVector = str_repeat("", $initVectorSize); } else { if (!is_string($initVector) || strlen($initVector) != $initVectorSize) { throw new Magento_Exception('Init vector must be a string of ' . $initVectorSize . ' bytes.'); } } } $this->_initVector = $initVector; } catch (Exception $e) { mcrypt_module_close($this->_handle); throw $e; } mcrypt_generic_init($this->_handle, $key, $initVector); }
/** * Decryption of data * * @param string $data Data to be decrypted * @param bool|string $key Key, if not specified - system key will be used * * @return bool|mixed */ function decrypt($data, $key = false) { if (!$this->encrypt_support) { return $data; } if (!is_resource($this->td)) { $this->td = mcrypt_module_open(MCRYPT_BLOWFISH, '', 'cbc', ''); $this->key = mb_substr($this->key, 0, mcrypt_enc_get_key_size($this->td)); $this->iv = mb_substr(md5($this->iv), 0, mcrypt_enc_get_iv_size($this->td)); } if ($key === false) { $key = $this->key; } else { $key = mb_substr(md5($this->key) . md5($key), 0, mcrypt_enc_get_key_size($this->td)); } mcrypt_generic_init($this->td, $key, $this->iv); errors_off(); $decrypted = @unserialize(mdecrypt_generic($this->td, $data)); errors_on(); mcrypt_generic_deinit($this->td); if (is_array($decrypted) && $decrypted['key'] == $key) { return $decrypted['data']; } else { return false; } }
/** * 实例化类库 * * @param string $secret_key 加密的安全码 * * @return void */ public function __construct($secret_key) { $this->td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_ECB, ''); $this->iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_DEV_RANDOM); $this->ks = mcrypt_enc_get_key_size($this->td); $this->key = substr(md5($secret_key), 0, $this->ks); }
/** * Initialize mcrypt module * * @param string $key cipher private key * @return Varien_Crypt_Mcrypt */ public function init($key) { if (!$this->getCipher()) { $this->setCipher(MCRYPT_BLOWFISH); } if (!$this->getMode()) { $this->setMode(MCRYPT_MODE_ECB); } $this->setHandler(mcrypt_module_open($this->getCipher(), '', $this->getMode(), '')); if (!$this->getInitVector()) { if (MCRYPT_MODE_CBC == $this->getMode()) { $this->setInitVector(substr(md5(mcrypt_create_iv(mcrypt_enc_get_iv_size($this->getHandler()), MCRYPT_RAND)), -mcrypt_enc_get_iv_size($this->getHandler()))); } else { $this->setInitVector(mcrypt_create_iv(mcrypt_enc_get_iv_size($this->getHandler()), MCRYPT_RAND)); } } $maxKeySize = mcrypt_enc_get_key_size($this->getHandler()); if (strlen($key) > $maxKeySize) { // strlen() intentionally, to count bytes, rather than characters $this->setHandler(null); throw new Varien_Exception('Maximum key size must be smaller ' . $maxKeySize); } mcrypt_generic_init($this->getHandler(), $key, $this->getInitVector()); return $this; }
public function authenticate(array $credentials) { $mcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($mcrypt), MCRYPT_DEV_RANDOM); mcrypt_generic_init($mcrypt, $this->cryptPassword, $iv); $url = $this->getUrl($credentials[self::USERNAME], $credentials[self::PASSWORD], $mcrypt, $iv); try { $res = $this->httpClient->get($url)->send(); } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) { if ($e->getResponse()->getStatusCode() === 403) { throw new \Nette\Security\AuthenticationException("User '{$credentials[self::USERNAME]}' not found.", self::INVALID_CREDENTIAL); } elseif ($e->getResponse()->getStatusCode() === 404) { throw new \Nette\Security\AuthenticationException("Invalid password.", self::IDENTITY_NOT_FOUND); } else { throw $e; } } $responseBody = trim(mdecrypt_generic($mcrypt, $res->getBody(TRUE))); $apiData = Json::decode($responseBody); $user = $this->db->table('users')->where('id = ?', $apiData->id)->fetch(); $registered = new \DateTimeImmutable($apiData->registered->date, new \DateTimeZone($apiData->registered->timezone)); $userData = array('username' => $credentials[self::USERNAME], 'password' => $this->calculateAddonsPortalPasswordHash($credentials[self::PASSWORD]), 'email' => $apiData->email, 'realname' => $apiData->realname, 'url' => $apiData->url, 'signature' => $apiData->signature, 'language' => $apiData->language, 'num_posts' => $apiData->num_posts, 'apiToken' => $apiData->apiToken, 'registered' => $registered->getTimestamp()); if (!$user) { $userData['id'] = $apiData->id; $userData['group_id'] = 4; $this->db->table('users')->insert($userData); $user = $this->db->table('users')->where('username = ?', $credentials[self::USERNAME])->fetch(); } else { $user->update($userData); } return $this->createIdentity($user); }
public function decrypt($encrypted, $is_id = false) { static $_map = array(); if ($is_id) { $len = strlen($encrypted); $tmp = ''; for ($i = 0; $i < $len; $i = $i + 2) { $tmp = $tmp . chr(hexdec($encrypted[$i] . $encrypted[$i + 1])); } $encrypted = $tmp; } else { $encrypted = base64_decode($encrypted); } $hashkey = md5($encrypted . $this->key); if (isset($_map[$hashkey])) { return $_map[$hashkey]; } $key = str_pad($this->key, 24, '0'); $td = mcrypt_module_open(MCRYPT_3DES, '', 'ecb', ''); $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); $ks = mcrypt_enc_get_key_size($td); @mcrypt_generic_init($td, $key, $iv); $decrypted = mdecrypt_generic($td, $encrypted); mcrypt_generic_deinit($td); mcrypt_module_close($td); $y = $this->pkcs5_unpad($decrypted); if ($is_id) { $y = base_convert($y, 36, 10); } $_map[$hashkey] = $y; return $y; }
public static function createEncryptIv() { $td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_OFB, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM); mcrypt_module_close($td); return $iv; }
function ssl_encode($data, $key = '') { // Use the Encrypt.php function get_key to encode the data. $key = $this->get_key($key); // Set a random salt $salt = substr(md5(mt_rand(), true), 8); $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $pad = $block - strlen($data) % $block; $data = $data . str_repeat(chr($pad), $pad); // Setup encryption parameters $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_CBC, ""); $key_len = mcrypt_enc_get_key_size($td); $iv_len = mcrypt_enc_get_iv_size($td); $total_len = $key_len + $iv_len; $salted = ''; $dx = ''; // Salt the key and iv while (strlen($salted) < $total_len) { $dx = md5($dx . $key . $salt, true); $salted .= $dx; } $key = substr($salted, 0, $key_len); $iv = substr($salted, $key_len, $iv_len); mcrypt_generic_init($td, $key, $iv); $encrypted_data = mcrypt_generic($td, $data); mcrypt_generic_deinit($td); mcrypt_module_close($td); return chunk_split(base64_encode('Salted__' . $salt . $encrypted_data), 32, "\n"); }
public function salt() { $td = mcrypt_module_open(MCRYPT_RIJNDAEL_256, "", MCRYPT_MODE_CBC, ""); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_URANDOM); $hash = hash("Whirlpool", $iv); return $hash; }
public function computeSign($sharedSecret) { if (!$this->isValid) { throw new Exception(__METHOD__ . ": Message was not validated."); } try { // ak mame zadany shared secret v hexa tvare tak ho prevedieme na 32 bytovy string if (strlen($sharedSecret) == 64) { $sharedSecret = pack('H*', $sharedSecret); } $base = $this->GetSignatureBase(); $bytesHash = sha1($base, TRUE); // vezmeme prvych 16 bytov $bytesHash = substr($bytesHash, 0, 16); $aes = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($aes), MCRYPT_RAND); mcrypt_generic_init($aes, $sharedSecret, $iv); $bytesSign = mcrypt_generic($aes, $bytesHash); mcrypt_generic_deinit($aes); mcrypt_module_close($aes); $sign = strtoupper(bin2hex($bytesSign)); } catch (Exception $e) { return FALSE; } return $sign; }
public static function getiv($cipher = 'twofish', $mode = 'cfb') { $td = mcrypt_module_open($cipher, '', $mode, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_module_close($td); return $iv; }
public static function decrypt($varValue, $clesCryptage = null) { self::initialize(); // Recursively decrypt arrays if (is_array($varValue)) { foreach ($varValue as $k => $v) { $varValue[$k] = self::decrypt(urldecode($v)); } return $varValue; } elseif ($varValue == '') { return ''; } $varValue = base64_decode($varValue); $ivsize = mcrypt_enc_get_iv_size(self::$resTd); $iv = substr($varValue, 0, $ivsize); $varValue = substr($varValue, $ivsize); if ($varValue == '') { return ''; } if ($clesCryptage === null) { $clesCryptage = self::$clesCryptage; } mcrypt_generic_init(self::$resTd, md5($clesCryptage), $iv); $strDecrypted = mdecrypt_generic(self::$resTd, $varValue); mcrypt_generic_deinit(self::$resTd); if (strpos($strDecrypted, "%") !== false) { return urldecode($strDecrypted); } else { return $strDecrypted; } }
function phpFreaksCrypto($key = 'a843l?nv89rjfd}O(jdnsleken0', $iv = false, $algorithm = 'tripledes', $mode = 'ecb') { if (extension_loaded('mcrypt') === FALSE) { //$prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : ''; //dl($prefix . 'mcrypt.' . PHP_SHLIB_SUFFIX) or die('The Mcrypt module could not be loaded.'); die('The Mcrypt module is not loaded and is required.'); } if ($mode != 'ecb' && $iv === false) { /* the iv must remain the same from encryption to decryption and is usually passed into the encrypted string in some form, but not always. */ die('In order to use encryption modes other then ecb, you must specify a unique and consistent initialization vector.'); } // set mcrypt mode and cipher $this->td = mcrypt_module_open($algorithm, '', $mode, ''); // Unix has better pseudo random number generator then mcrypt, so if it is available lets use it! //$random_seed = strstr(PHP_OS, "WIN") ? MCRYPT_RAND : MCRYPT_DEV_RANDOM; $random_seed = MCRYPT_RAND; // if initialization vector set in constructor use it else, generate from random seed $iv = $iv === false ? mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), $random_seed) : substr($iv, 0, mcrypt_enc_get_iv_size($this->td)); // get the expected key size based on mode and cipher $expected_key_size = mcrypt_enc_get_key_size($this->td); // we dont need to know the real key, we just need to be able to confirm a hashed version $key = substr(md5($key), 0, $expected_key_size); // initialize mcrypt library with mode/cipher, encryption key, and random initialization vector mcrypt_generic_init($this->td, $key, $iv); }
/** * Encrypt data for security * * @param mixed $data * @return string */ public static function encrypt($data) { // Don't do anything with empty data $data = trim($data); if (empty($data)) { return null; } // Check if encryption was turned off if (MagebridgeModelConfig::load('encryption') == 0) { return $data; } // Check if SSL is already in use, so encryption is not needed if (MagebridgeModelConfig::load('protocol') == 'https') { return $data; } // Check for mcrypt if (!function_exists('mcrypt_get_iv_size') || !function_exists('mcrypt_cfb')) { return $data; } // Generate a random key $random = str_shuffle('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'); $key = MageBridgeEncryptionHelper::getSaltedKey($random); try { $td = mcrypt_module_open(MCRYPT_CAST_256, '', 'ecb', ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key, $iv); $encrypted = mcrypt_generic($td, $data); $encoded = MageBridgeEncryptionHelper::base64_encode($encrypted); } catch (Exception $e) { Mage::getSingleton('magebridge/debug')->error("Error while decrypting: " . $e->getMessage()); return null; } return $encoded . '|=|' . $random; }
public function __construct($key, $algorithm, $mode = 'ecb', $iv = false) { /* In non-ECB mode, an initialization vector is required. */ if ($mode != 'ecb' && $iv === false) { return false; } /* Try to open the encryption module. */ $this->_td = mcrypt_module_open($algorithm, '', $mode, ''); if ($this->_td === false) { return false; } /* Use UNIX random number generator if available. */ if (strstr(PHP_OS, 'WIN') !== false) { $randomSeed = MCRYPT_RAND; } else { $randomSeed = MCRYPT_DEV_RANDOM; } /* If an initialization vector was not specified, create one; * otherwise ensure that the specified IV is the proper size. */ if ($iv === false) { $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->_td), $randomSeed); } else { $iv = substr($iv, 0, mcrypt_enc_get_iv_size($this->_td)); } /* Trim the key to the maximum allowed key size. */ $key = substr($key, 0, mcrypt_enc_get_key_size($this->_td)); /* Initialize the MCrypt library. */ mcrypt_generic_init($this->_td, $key, $iv); }
public function decrypt($data) { // if($this->input->ip_address() == '10.52.66.172') { // var_dump($data); // die; // } $key = "secret"; $td = mcrypt_module_open(MCRYPT_DES, "", MCRYPT_MODE_ECB, ""); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $key, $iv); // mcrypt_generic_deinit($td); // if($this->input->ip_address() == '10.52.66.172') { // var_dump($data); // die; // } $data = mdecrypt_generic($td, base64_decode($data)); // if($this->input->ip_address() == '10.52.66.172') { // var_dump($data); // die; // } mcrypt_generic_deinit($td); if (substr($data, 0, 1) != '!') { return false; } $data = substr($data, 1, strlen($data) - 1); return unserialize($data); }
private function __construct() { if (!function_exists('mcrypt_module_open')) { throw new Hayate_Exception(sprintf(_('%s: mcrypt extension is missing.'), __CLASS__)); } switch (self::ALGO) { case 'aes': $algo = MCRYPT_RIJNDAEL_256; break; case 'tripledes': $algo = MCRYPT_TRIPLEDES; break; case 'blowfish': $algo = MCRYPT_BLOWFISH; break; default: throw new Hayate_Exception(sprintf(_('%s is not supported, please use "aes", "tripledes" or "blowfish"'), self::ALGO)); } // initialize mcrypt $this->mcrypt = mcrypt_module_open($algo, '', MCRYPT_MODE_CBC, ''); // calculate IV size $this->ivsize = mcrypt_enc_get_iv_size($this->mcrypt); // calculate key max key length $this->maxKeysize = mcrypt_enc_get_key_size($this->mcrypt); $config = Hayate_Config::getInstance(); if ($config->get('core.secret_key', false)) { $this->setKey($config->core->secret_key); } }
public function enkripsi($algoritma, $mode, $secretkey, $fileplain) { /* Membuka Modul untuk memilih Algoritma & Mode Operasi */ $td = mcrypt_module_open($algoritma, '', $mode, ''); /* Inisialisasi IV dan Menentukan panjang kunci yang digunakan */ $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); $ks = mcrypt_enc_get_key_size($td); /* Menghasilkan Kunci */ $key = $secretkey; //echo "kuncinya : ". $key. "<br>"; /* Inisialisasi */ mcrypt_generic_init($td, $key, $iv); /* Enkripsi Data, dimana hasil enkripsi harus di encode dengan base64.\ Hal ini dikarenakan web browser tidak dapat membaca karakter-karakter\ ASCII dalam bentuk simbol-simbol */ $buffer = $fileplain; $encrypted = mcrypt_generic($td, $buffer); $encrypted1 = base64_encode($iv) . ";" . base64_encode($encrypted); $encrypted2 = base64_encode($encrypted1); $filecipher = $encrypted2; /* Menghentikan proses enkripsi dan menutup modul */ mcrypt_generic_deinit($td); mcrypt_module_close($td); return $filecipher; }
public function computeSign($sharedSecret) { if (!$this->isValid) { throw new Exception(__METHOD__ . ": Message was not validated."); } try { $bytesHash = sha1($this->GetSignatureBase(), true); $sharedSecret = pack('H*', $sharedSecret); // uprava pre PHP < 5.0 if (strlen($bytesHash) != 20) { $bytes = ""; for ($i = 0; $i < strlen($bytesHash); $i += 2) { $bytes .= chr(hexdec(substr($str, $i, 2))); } $bytesHash = $bytes; } $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_ECB, ""); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($cipher), MCRYPT_RAND); mcrypt_generic_init($cipher, $sharedSecret, $iv); $text = $this->pad(substr($bytesHash, 0, 16), mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB)); $bytesSign = mcrypt_generic($cipher, $text); mcrypt_generic_deinit($cipher); mcrypt_module_close($cipher); $sign = substr(strtoupper(bin2hex($bytesSign)), 0, 32); } catch (Exception $e) { return false; } return $sign; }
/** * Store an encrypted cookie * * @param string $cookieName * @param mixed $cookieValue * @param int $expiry default stores just for the browser session */ public static function set($cookieName, $cookieValue, $expiry = 0) { if (isset($_COOKIE['synsec'])) { $synsec = $_COOKIE['synsec']; } else { $synsec = Tools::randomString('12'); } if ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') && (!isset($_SERVER['HTTP_X_FORWARDED_PROTO']) || $_SERVER['HTTP_X_FORWARDED_PROTO'] != 'https')) { $ssl = false; } else { $ssl = true; } setcookie('synsec', $synsec, time() + 60 * 60 * 24 * 30, '/', $_SERVER['HTTP_HOST'], $ssl, true); $synsec .= 'synErgy' . self::$token; /* Open the cipher */ $td = mcrypt_module_open('rijndael-256', '', 'ofb', ''); /* Create the IV and determine the keysize length, use MCRYPT_RAND * on Windows instead */ $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM); $ks = mcrypt_enc_get_key_size($td); /* Create key */ $key = substr(md5($synsec), 0, $ks); /* Intialize encryption */ mcrypt_generic_init($td, $key, $iv); /* Encrypt data */ $encrypted = mcrypt_generic($td, serialize($cookieValue)); # Store our secure cookie setcookie($cookieName, trim(base64_encode($iv . '|' . $encrypted)), $expiry, '/', $_SERVER['HTTP_HOST'], $ssl, true); /* Terminate encryption handler */ mcrypt_generic_deinit($td); }
/** * @param array $options * * @throws \InvalidArgumentException */ public function __construct(array $options) { //Options $this->key = isset($options['secret_key']) ? (string) $options['secret_key'] : ''; $this->algorithm = isset($options['algorithm']) ? (string) $options['algorithm'] : self::DEFAULT_ALGORITHM; $this->mode = isset($options['mode']) ? (string) $options['mode'] : self::DEFAULT_MODE; $this->randomInitializationVector = isset($options['random_initialization_vector']) ? (bool) $options['random_initialization_vector'] : self::DEFAULT_RANDOM_INITIALIZATION_VECTOR; $this->base64 = isset($options['base64']) ? (bool) $options['base64'] : self::DEFAULT_BASE64; $this->base64UrlSafe = isset($options['base64_url_safe']) ? (bool) $options['base64_url_safe'] : self::DEFAULT_BASE64_URL_SAFE; //Initialize encryption if ($this->mode == MCRYPT_MODE_STREAM) { throw new \InvalidArgumentException('Stream mode not supported'); } $this->module = @mcrypt_module_open($this->algorithm, '', $this->mode, ''); if ($this->module === false) { throw new \InvalidArgumentException('Unknown algorithm/mode'); } $this->checkKey(); $this->initializationVectorSize = mcrypt_enc_get_iv_size($this->module); if ($this->randomInitializationVector) { $this->mcryptRandomMethod = defined('MCRYPT_DEV_URANDOM') ? MCRYPT_DEV_URANDOM : MCRYPT_DEV_RANDOM; } else { $this->fixedInitializationVector = str_repeat(self::FIXED_INITIALIZATION_VECTOR_CHAR, $this->initializationVectorSize); } }
public function __construct($algorithm, $mode) { if (!($this->crResource = mcrypt_module_open($algorithm, null, $mode, null))) { throw new WrongStateException('Mcrypt Module did not open.'); } $this->iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->crResource), MCRYPT_DEV_URANDOM); $this->keySize = mcrypt_enc_get_key_size($this->crResource); }
function __construct() { $this->td = mcrypt_module_open('rijndael-256', '', 'ofb', ''); $this->iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_DEV_RANDOM); $this->ks = mcrypt_enc_get_key_size($this->td); //$this->key = substr(md5('very secret key'), 0, $this->ks); $this->key = substr(sha1('very secret key'), 0, $this->ks); }
/** * @param string $key Human readable key * @param string $cipher Cipher/algorithm * @param string $mode Crypt mode */ public function __construct($key = 'top secret key', $cipher = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_ECB) { $this->module = mcrypt_module_open($cipher, '', $mode, ''); $this->iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->module), MCRYPT_DEV_RANDOM); $keySize = mcrypt_enc_get_key_size($this->module); // todo improve to hex $this->key = substr(md5($key), 0, $keySize); }
public function generate_iv() { global $conf; $td = mcrypt_module_open($conf->encrypt_algo, '', $conf->encrypt_mode, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_URANDOM); mcrypt_module_close($td); return $iv; }
/** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Mage * @package Mage * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ function decr($text, $key) { $h = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, ''); $v = mcrypt_create_iv(mcrypt_enc_get_iv_size($h), MCRYPT_RAND); mcrypt_generic_init($h, $key, $v); $decripted = mdecrypt_generic($h, base64_decode($text)); return $decripted; }
function __construct($key = '') { $this->_key = $key; $this->_cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); $this->_ivSize = mcrypt_enc_get_iv_size($this->_cipher); $tmpIV = bin2hex(mcrypt_create_iv($this->_ivSize)); $this->_iv = substr($tmpIV, 0, $this->_ivSize); }
public static function decrypt($data) { $mcrypt_module = mcrypt_module_open(MCRYPT_TRIPLEDES, '', 'ecb', ''); $mcrypt_iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($mcrypt_module), MCRYPT_RAND); $decrypted = mcrypt_decrypt(MCRYPT_TRIPLEDES, self::$key, base64_decode($data), 'ecb', $mcrypt_iv); mcrypt_module_close($mcrypt_module); return self::pkcs5_unpad($decrypted); }
function __construct() { $this->resource = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, ''); $ks = mcrypt_enc_get_key_size($this->resource); $this->key = substr(md5($this->key), 0, $ks); $ivsize = mcrypt_enc_get_iv_size($this->resource); $this->iv = substr(md5($this->key), 0, $ivsize); }
public function __construct($key) { $td = mcrypt_module_open('des', '', 'ecb', ''); $key = substr($key, 0, mcrypt_enc_get_key_size($td)); $iv_size = mcrypt_enc_get_iv_size($td); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); mcrypt_generic_init($td, $key, $iv); $this->td = $td; }