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


PHP PKCS7Encoder::decode方法代碼示例

本文整理匯總了PHP中PKCS7Encoder::decode方法的典型用法代碼示例。如果您正苦於以下問題:PHP PKCS7Encoder::decode方法的具體用法?PHP PKCS7Encoder::decode怎麽用?PHP PKCS7Encoder::decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PKCS7Encoder的用法示例。


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

示例1: decrypt

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

示例2: 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

示例3: decrypt

 /**
  * 對密文進行解密
  *
  * @param string $encrypted 需要解密的密文
  * @param string $corp_id
  * @return string 解密得到的明文
  */
 public function decrypt($encrypted, $corp_id)
 {
     try {
         //使用BASE64對需要解密的字符串進行解碼
         $cipherText = base64_decode($encrypted);
         $iv = substr($this->_key, 0, self::INIT_VECTOR_SIZE);
         $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, $cipherText, MCRYPT_MODE_CBC, $iv);
     } catch (\Exception $e) {
         return false;
     }
     try {
         //去除補位字符
         $result = PKCS7Encoder::decode($decrypted);
         //去除16位隨機字符串,網絡字節序和AppId
         if (strlen($result) < self::RANDOM_STRING_LEN) {
             return '';
         }
         $content = substr($result, self::RANDOM_STRING_LEN);
         list(, $xmlContentLen) = unpack('N', substr($content, 0, 4));
         $xmlContent = substr($content, 4, $xmlContentLen);
         $fromCorpID = substr($content, $xmlContentLen + 4);
     } catch (\Exception $e) {
         return false;
     }
     if ($fromCorpID != $corp_id) {
         return false;
     }
     return $xmlContent;
 }
開發者ID:cdcchen,項目名稱:wechat-client,代碼行數:36,代碼來源:PrpCrypt.php

示例4: decrypt

 /**
  * 對密文進行解密
  * @param string $encrypted 需要解密的密文
  * @return string 解密得到的明文
  */
 public function decrypt($encrypted, $appid)
 {
     try {
         //使用BASE64對需要解密的字符串進行解碼
         $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_appid = substr($content, $xml_len + 4);
         if (!$appid) {
             $appid = $from_appid;
         }
         //如果傳入的appid是空的,則認為是訂閱號,使用數據中提取出來的appid
     } catch (Exception $e) {
         //print $e;
         return array(ErrorCode::$IllegalBuffer, null);
     }
     if ($from_appid != $appid) {
         return array(ErrorCode::$ValidateAppidError, null);
     }
     //不注釋上邊兩行,避免傳入appid是錯誤的情況
     return array(0, $xml_content, $from_appid);
     //增加appid,為了解決後麵加密回複消息的時候沒有appid的訂閱號會無法回複
 }
開發者ID:lubaogui,項目名稱:yii2-wechat,代碼行數:48,代碼來源:Prpcrypt.php

示例5: decrypt

 /**
  * 對密文進行解密
  * @param string $encrypted 需要解密的密文
  * @return string 解密得到的明文
  */
 public function decrypt($encrypted)
 {
     try {
         //使用BASE64對需要解密的字符串進行解碼
         $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 null;
     }
     try {
         //去除補位字符
         $pkc_encoder = new PKCS7Encoder();
         $result = $pkc_encoder->decode($decrypted);
         //去除16位隨機字符串,網絡字節序和機身編號
         if (strlen($result) < 16) {
             return "";
         }
         $content = substr($result, 16, strlen($result));
         $len_list = unpack("N", substr($content, 0, 4));
         $command_len = $len_list[1];
         $command_content = substr($content, 4, $command_len);
     } catch (Exception $e) {
         //print $e;
         return null;
     }
     return $command_content;
 }
開發者ID:mysterin,項目名稱:myutils,代碼行數:38,代碼來源:aes.php

示例6: decrypt

 /**
  * @param string $encrypted 密文
  * @param string $corpid    
  * @param boolean $validCorpid 是否驗證corpid,默認驗證
  * @return NULL|string
  */
 public function decrypt($encrypted, $corpid, $validCorpid = true)
 {
     try {
         //使用BASE64對需要解密的字符串進行解碼
         $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) {
         $this->err = new PrpcryptError($e->getCode(), $e->getMessage(), $e->getLine(), $e->getFile(), $e->getTrace());
         return null;
     }
     try {
         //去除補位字符
         $pkc_encoder = new PKCS7Encoder();
         $result = $pkc_encoder->decode($decrypted);
         //去除16位隨機字符串,網絡字節序和AppId
         if (strlen($result) < 16) {
             $this->err = new PrpcryptError(PrpcryptError::RESULT_LENGHT_LESS_THAN_16, 'result length is less than 16', __LINE__, __FILE__, debug_backtrace());
             return null;
         }
         $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) {
         $this->err = new PrpcryptError($e->getCode(), $e->getMessage(), $e->getLine(), $e->getFile(), $e->getTrace());
         return null;
     }
     if ($validCorpid && $from_corpid != $corpid) {
         $this->err = new PrpcryptError(PrpcryptError::CORPID_IS_NOT_VALID, "coprid given is :{$corpid}, but the from corpid is : {$from_corpid}", __LINE__, __FILE__, debug_backtrace());
         return null;
     } else {
         return $xml_content;
     }
 }
開發者ID:gtyd,項目名稱:jira,代碼行數:47,代碼來源:Prpcrypt.php

示例7: decrypt

 /**
  * 對密文進行解密
  * @param string $encrypted 需要解密的密文
  * @return string 解密得到的明文
  */
 public function decrypt($encrypted, $corpid)
 {
     try {
         //使用BASE64對需要解密的字符串進行解碼
         $ciphertext_dec = base64_decode($encrypted);
         $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
         $iv = trim(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 {
         //去除補位字符
         \Log::info('tt');
         $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 = trim(substr($content, 4, $xml_len));
         $from_corpid = trim(substr($content, $xml_len + 4));
     } catch (Exception $e) {
         print $e;
         return array(ErrorCode::$IllegalBuffer, null);
     }
     \Log::info("from:" . $xml_content);
     \Log::info("corp:" . $corpid);
     //TODO 檢查不通過 注釋掉
     //		if ($from_corpid != $corpid)
     //			return array(ErrorCode::$ValidateCorpidError, null);
     \Log::info("corpID:" . $corpid);
     \Log::info("fromCorpId" . $from_corpid);
     return array(0, $xml_content);
 }
開發者ID:hachi-zzq,項目名稱:laravel-zzq,代碼行數:47,代碼來源:pkcs7Encoder.php


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