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($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); }
public function decrypt($encrypted, $corpid) { try { $ciphertext_dec = base64_decode($encrypted); $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); $iv = substr($this->key, 0, 16); mcrypt_generic_init($module, $this->key, $iv); $decrypted = mdecrypt_generic($module, $ciphertext_dec); mcrypt_generic_deinit($module); mcrypt_module_close($module); } catch (Exception $e) { return array(ErrorCode::$DecryptAESError, null); } try { //去除补位字符 $pkc_encoder = new PKCS7Encoder(); $result = $pkc_encoder->decode($decrypted); //去除16位随机字符串,网络字节序和AppId if (strlen($result) < 16) { return ""; } $content = substr($result, 16, strlen($result)); $len_list = unpack("N", substr($content, 0, 4)); $xml_len = $len_list[1]; $xml_content = substr($content, 4, $xml_len); $from_corpid = substr($content, $xml_len + 4); } catch (Exception $e) { print $e; return array(ErrorCode::$DecryptAESError, null); } if ($from_corpid != $corpid) { return array(ErrorCode::$ValidateSuiteKeyError, null); } return array(0, $xml_content); }
/** * @param string $encrypted * @return string */ protected function mdecrypt($encrypted) { $this->encryptInit(); $decrypted = mdecrypt_generic($this->getEncryptionDescriptor(), $encrypted); $this->encryptDeinit(); return $decrypted; }
/** * {@inheritdoc} */ public function decrypt($data) { $this->init(); $data = trim(mdecrypt_generic($this->module, base64_decode($data))); $this->close(); return $data; }
public function decrypt($text) { mcrypt_generic_init($this->td, $this->key, $this->iv); $decrypted = mdecrypt_generic($this->td, $text); mcrypt_generic_deinit($this->td); return $decrypted; }
public static function decrypt($string, $key = null, $salt = null, $iv = null) { $config = ConfigManager::getConfig('Crypto', 'AES256')->AuxConfig; if ($key === null) { $key = $config->key; } if ($salt === null) { $salt = $config->salt; } if ($iv === null) { $iv = $config->iv; } $td = mcrypt_module_open('rijndael-128', '', MCRYPT_MODE_CBC, ''); $ks = mcrypt_enc_get_key_size($td); $bs = mcrypt_enc_get_block_size($td); $iv = substr(hash("sha256", $iv), 0, $bs); // Create key $key = Crypto::pbkdf2("sha512", $key, $salt, $config->pbkdfRounds, $ks); // Initialize encryption module for decryption mcrypt_generic_init($td, $key, $iv); $decryptedString = ""; // Decrypt encrypted string try { if (ctype_xdigit($string)) { $decryptedString = trim(mdecrypt_generic($td, pack("H*", $string))); } } catch (ErrorException $e) { } // Terminate decryption handle and close module mcrypt_generic_deinit($td); mcrypt_module_close($td); // Show string return $decryptedString; }
/** */ public function decrypt($text) { mcrypt_generic_init($this->_mcrypt, $this->key, empty($this->iv) ? str_repeat('0', Horde_Crypt_Blowfish::IV_LENGTH) : $this->iv); $out = mdecrypt_generic($this->_mcrypt, $this->_pad($text, true)); mcrypt_generic_deinit($this->_mcrypt); return $this->_unpad($out); }
/** * 要解密的字符串 * * @param string $string 需要解密的字符 * * @return string */ public function decode($string) { mcrypt_generic_init($this->td, $this->key, $this->iv); $data = mdecrypt_generic($this->td, base64_decode($string)); mcrypt_generic_deinit($this->td); return trim($data); }
public function decrypt($data) { mcrypt_generic_init($this->module, $this->key, $this->iv); $ret = mdecrypt_generic($this->module, $data); mcrypt_generic_deinit($this->module); return rtrim($ret, ""); }
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; } }
public function decrypt($encrypted, $appid = '') { try { $encrypted = base64_decode($encrypted); $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); $iv = substr($this->key, 0, 16); mcrypt_generic_init($td, $this->key, $iv); $decrypted = mdecrypt_generic($td, $encrypted); mcrypt_generic_deinit($td); mcrypt_module_close($td); } catch (Exception $e) { throw new Exception($e->getMessage(), ErrorCode::$DecryptAESError); } try { $result = self::PKCS7Decode($decrypted); if (strlen($result) < 16) { throw new Exception('PKCS7Decode length less than 16', ErrorCode::$IllegalBuffer); } $content = substr($result, 16); $lenlist = unpack('N', substr($content, 0, 4)); $xmlLen = $lenlist[1]; $xmlData = substr($content, 4, $xmlLen); $fromId = substr($content, $xmlLen + 4); } catch (Exception $e) { throw new Exception($e->getMessage(), ErrorCode::$IllegalBuffer); } if ($fromId != $appid) { throw new Exception('Unvalidated Appid.', ErrorCode::$ValidateAppidError); } else { return $xmlData; } }
/** * 对密文进行解密 * @param string $encrypt 密文 * @return string 明文 */ public function decrypt($encrypt) { //BASE64解码 $encrypt = base64_decode($encrypt); //打开加密算法模块 $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); //初始化加密算法模块 mcrypt_generic_init($td, $this->cyptKey, substr($this->cyptKey, 0, 16)); //执行解密 $decrypt = mdecrypt_generic($td, $encrypt); //去除PKCS7补位 $decrypt = self::PKCS7Decode($decrypt, mcrypt_enc_get_key_size($td)); //关闭加密算法模块 mcrypt_generic_deinit($td); mcrypt_module_close($td); if (strlen($decrypt) < 16) { throw new \Exception("非法密文字符串!"); } //去除随机字符串 $decrypt = substr($decrypt, 16); //获取网络字节序 $size = unpack("N", substr($decrypt, 0, 4)); $size = $size[1]; //APP_ID $appid = substr($decrypt, $size + 4); //验证APP_ID if ($appid !== $this->appId) { throw new \Exception("非法APP_ID!"); } //明文内容 $text = substr($decrypt, 4, $size); return $text; }
public function decrypt($cypherText) { /* Base64-decode the encrypted data and decrypt it. */ $plainText = mdecrypt_generic($this->_td, base64_decode($cypherText)); /* Remove any \0 padding. */ return rtrim($plainText, ""); }
public function decrypt($ciphertext) { mcrypt_generic_init($this->encrypter, $this->key, substr($this->key, 0, 16)); $origData = mdecrypt_generic($this->encrypter, $ciphertext); mcrypt_generic_deinit($this->encrypter); return pkcs5unPadding($origData); }
function decryptNET3DES($key, $iv, $text) { if (empty($text)) { return ""; } $td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_ECB, ''); // 把key值补充完整,在PHP里面如果key值不够24位剩下的会自动补0,但是在.net中,会做一个循环把前面的值补充到后面补够24位,所以这里强制补前面的字符 $key_add = 24 - strlen($key); $key .= substr($key, 0, $key_add); mcrypt_generic_init($td, $key, $iv); $decrypt_text = mdecrypt_generic($td, $text); mcrypt_generic_deinit($td); mcrypt_module_close($td); //去掉padding的尾巴,因为.net中默认的padding是PKCS7,而php中默认的padding是zero,所以在.net使用默认的情况下,要将php程序的padding重新设置 $block = mcrypt_get_block_size('tripledes', 'ecb'); $packing = ord($decrypt_text[strlen($decrypt_text) - 1]); if ($packing and $packing < $block) { for ($P = strlen($decrypt_text) - 1; $P >= strlen($decrypt_text) - $packing; $P--) { if (ord($decrypt_text[$P]) != $packing) { $packing = 0; } } } $decrypt_text = substr($decrypt_text, 0, strlen($decrypt_text) - $packing); return $decrypt_text; }
public function decrypt($msg, $k, $base64 = false) { if ($base64) { $msg = base64_decode($msg); } if (!($td = mcrypt_module_open('rijndael-256', '', 'ctr', ''))) { return false; } $iv = substr($msg, 0, 32); $mo = strlen($msg) - 32; $em = substr($msg, $mo); $msg = substr($msg, 32, strlen($msg) - 64); $mac = $this->pbkdf2($iv . $msg, $k, 1000, 32); if ($em !== $mac) { return false; } if (mcrypt_generic_init($td, $k, $iv) !== 0) { return false; } $msg = mdecrypt_generic($td, $msg); $msg = unserialize($msg); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $msg; }
public static function decrypt($data) { $crypteddata = base64_decode($data); // HMAC is the last 32 bytes $givenhmac = substr($crypteddata, -32); // now we check that the payload actually matches the HMAC $crypteddata = substr($crypteddata, 0, -32); // data without the HMAC $knownhmac = hash_hmac('sha256', $crypteddata, Config::$a['crypto']['seed'], true); // compare the HMACs in a side-channel safe way if (!self::constantTimeCompare($knownhmac, $givenhmac)) { return ''; } // the IV is the next 32 bytes, the actual size of the IV is not really // important since we get it dynamically $ivlength = mcrypt_get_iv_size('rijndael-256', 'ctr'); $iv = substr($crypteddata, -$ivlength); // everything else is the encrypted payload $crypteddata = substr($crypteddata, 0, -$ivlength); // pass in the IV so that decryption can work $crypt = self::initCrypt($iv); $ret = mdecrypt_generic($crypt['mod'], $crypteddata); mcrypt_generic_deinit($crypt['mod']); return $ret; }
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 function decrypt($encrypted, $appid) { try { $ciphertext_dec = base64_decode($encrypted); $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); $iv = substr($this->key, 0, 16); mcrypt_generic_init($module, $this->key, $iv); $decrypted = mdecrypt_generic($module, $ciphertext_dec); mcrypt_generic_deinit($module); mcrypt_module_close($module); } catch (Exception $e) { return array(ErrorCode::$DecryptAESError, NULL); } try { $pkc_encoder = new PKCS7Encoder(); $result = $pkc_encoder->decode($decrypted); if (strlen($result) < 16) { return ''; } $content = substr($result, 16, strlen($result)); $len_list = unpack('N', substr($content, 0, 4)); $xml_len = $len_list[1]; $xml_content = substr($content, 4, $xml_len); $from_appid = substr($content, $xml_len + 4); } catch (Exception $e) { print $e; return array(ErrorCode::$IllegalBuffer, NULL); } if ($from_appid != $appid) { return array(ErrorCode::$ValidateAppidError, NULL); } return array(0, $xml_content); }
static function decrypt($input, $base64 = true) { if (!$input || !strlen($input) > 0) { return null; } if (!($td = mcrypt_module_open('rijndael-256', '', 'ctr', ''))) { return null; } if ($base64) { $content = base64_decode($input); } else { $content = $input; } $iv = substr($content, 0, 32); $extract = substr($content, strlen($content) - 32); $content = substr($content, 32, strlen($content) - 64); $mac = self::pbkdf2($iv . $content, MSettings::$c_key, 1000, 32); if ($extract !== $mac) { return null; } if (mcrypt_generic_init($td, MSettings::$c_key, $iv) !== 0) { return null; } $content = mdecrypt_generic($td, $content); $content = unserialize($content); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $content; }
/** * Decrypt * * @return mixed string|null * @param object $value */ public function decrypt($value) { if (empty($value)) { return $value; } return str_replace("", '', trim(mdecrypt_generic($this->_handler, base64_decode((string) $value)))); }
/** * Decrypt * * @param string $data Data to decrypt * * @return string */ public function decrypt($data) { mcrypt_generic_init($this->module, $this->key, $this->iv); $decrypted = mdecrypt_generic($this->module, $data); mcrypt_generic_deinit($this->module); return trim($decrypted); }
function decrypt($encrypted_string) { /* remove any special characters then decrypt string using mcrypt and then trim null padding and then finally return the encrypted string */ return trim(mdecrypt_generic($this->td, base64_decode($encrypted_string))); }
public function decrypt($string) { $this->get_iv(); $decrypted_text = mdecrypt_generic($this->td, base64_decode($string)); mcrypt_generic_deinit($this->td); mcrypt_module_close($this->td); return $this->process($decrypted_text, 'clear'); }
/** * 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; }
/** * @param $encryptedData * @return string */ public function decrypt($encryptedData) { $initializationVector = substr($encryptedData, 0, $this->initializationVectorSize); mcrypt_generic_init($this->mcryptModule, $this->key, $initializationVector); $decryptedData = mdecrypt_generic($this->mcryptModule, substr($encryptedData, $this->initializationVectorSize)); mcrypt_generic_deinit($this->mcryptModule); return $this->unpad($decryptedData); }
/** @inheritdoc */ public function decrypt($cipherText) { mcrypt_generic_init($this->mcryptResource, $this->getKey(), $this->getIv()); $decrypted_and_padded_text = mdecrypt_generic($this->mcryptResource, $cipherText); mcrypt_generic_deinit($this->mcryptResource); $decrypted_text = $this->padder->unpad($decrypted_and_padded_text); return $decrypted_text; }
/** * @param $enc string */ public function decrypt($enc) { $this->genericInit(); $enc = base64_decode($enc); $dec = mdecrypt_generic($this->td, $enc); mcrypt_generic_deinit($this->td); return $dec; }
function desCypher($cypher, $key, $beginArray, $data) { mcrypt_generic_init($cypher, $key, base64_decode($beginArray)); $newDate = mdecrypt_generic($cypher, base64_decode($data)); mcrypt_generic_deinit($cypher); mcrypt_module_close($cypher); return rtrim($newDate, ""); }