本文整理匯總了PHP中PKCS7Encoder類的典型用法代碼示例。如果您正苦於以下問題:PHP PKCS7Encoder類的具體用法?PHP PKCS7Encoder怎麽用?PHP PKCS7Encoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了PKCS7Encoder類的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);
}
示例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);
}
示例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;
}
示例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的訂閱號會無法回複
}
示例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;
}
示例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;
}
}
示例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);
}