本文整理汇总了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);
}
示例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);
}
示例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);
}
示例4: mdecrypt
/**
* @param string $encrypted
* @return string
*/
protected function mdecrypt($encrypted)
{
$this->encryptInit();
$decrypted = mdecrypt_generic($this->getEncryptionDescriptor(), $encrypted);
$this->encryptDeinit();
return $decrypted;
}
示例5: decrypt
/**
* {@inheritdoc}
*/
public function decrypt($data)
{
$this->init();
$data = trim(mdecrypt_generic($this->module, base64_decode($data)));
$this->close();
return $data;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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, "");
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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, "");
}
示例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);
}