當前位置: 首頁>>代碼示例>>PHP>>正文


PHP mdecrypt_generic函數代碼示例

本文整理匯總了PHP中mdecrypt_generic函數的典型用法代碼示例。如果您正苦於以下問題:PHP mdecrypt_generic函數的具體用法?PHP mdecrypt_generic怎麽用?PHP mdecrypt_generic使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了mdecrypt_generic函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: authenticate

 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);
 }
開發者ID:newPOPE,項目名稱:web-addons.nette.org,代碼行數:32,代碼來源:NetteOrgAuthenticator.php

示例2: decrypt

 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);
 }
開發者ID:pollux1er,項目名稱:dlawebdev2,代碼行數:27,代碼來源:article.php

示例3: decrypt

 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);
 }
開發者ID:vincent067,項目名稱:openapi-demo-php,代碼行數:35,代碼來源:pkcs7Encoder.php

示例4: mdecrypt

 /**
  * @param string $encrypted
  * @return string
  */
 protected function mdecrypt($encrypted)
 {
     $this->encryptInit();
     $decrypted = mdecrypt_generic($this->getEncryptionDescriptor(), $encrypted);
     $this->encryptDeinit();
     return $decrypted;
 }
開發者ID:testinaweb,項目名稱:dynamic-crypto,代碼行數:11,代碼來源:DynamicDecrypter.php

示例5: decrypt

 /**
  * {@inheritdoc}
  */
 public function decrypt($data)
 {
     $this->init();
     $data = trim(mdecrypt_generic($this->module, base64_decode($data)));
     $this->close();
     return $data;
 }
開發者ID:rafrsr,項目名稱:crypto,代碼行數:10,代碼來源:MCryptEncryptor.php

示例6: decrypt

 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;
 }
開發者ID:HyuchiaDiego,項目名稱:Kirino,代碼行數:7,代碼來源:Crypt.php

示例7: decrypt

 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;
 }
開發者ID:Welvin,項目名稱:stingle,代碼行數:34,代碼來源:AES256.class.php

示例8: decrypt

 /**
  */
 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);
 }
開發者ID:evltuma,項目名稱:moodle,代碼行數:9,代碼來源:Mcrypt.php

示例9: decode

 /**
  * 要解密的字符串
  *
  * @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);
 }
開發者ID:3032441712,項目名稱:person,代碼行數:14,代碼來源:Data.php

示例10: decrypt

 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, "");
 }
開發者ID:Ronmi,項目名稱:fruit-cryptokit,代碼行數:7,代碼來源:Mcrypt.php

示例11: decrypt

 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;
     }
 }
開發者ID:SylvainSimon,項目名稱:Metinify,代碼行數:31,代碼來源:Encryption.php

示例12: decrypt

 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;
     }
 }
開發者ID:royalwang,項目名稱:Pyramid,代碼行數:32,代碼來源:Prpcrypt.php

示例13: decrypt

 /**
  * 對密文進行解密
  * @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;
 }
開發者ID:393197906,項目名稱:hummingbird,代碼行數:38,代碼來源:WechatCrypt.class.php

示例14: decrypt

 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, "");
 }
開發者ID:PublicityPort,項目名稱:OpenCATS,代碼行數:7,代碼來源:Encryption.php

示例15: decrypt

 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);
 }
開發者ID:victor-u,項目名稱:encryption-aes,代碼行數:7,代碼來源:aescrypter.php


注:本文中的mdecrypt_generic函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。