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


PHP mcrypt_generic_init函數代碼示例

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


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

示例1: enkripsi_plain2

function enkripsi_plain2($algoritma, $mode, $secretkey, $fileplain)
{
    /* Membuka Modul untuk memilih Algoritma & Mode Operasi */
    $td = mcrypt_module_open($algoritma, '', $mode, '');
    /* Inisialisasi IV dan Menentukan panjang kunci yang digunakan*/
    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    $ks = mcrypt_enc_get_key_size($td);
    /* Menghasilkan Kunci */
    $key = $secretkey;
    //echo "kuncinya : ". $key. "<br>";
    /* Inisialisasi */
    mcrypt_generic_init($td, $key, $iv);
    /* Enkripsi Data, dimana hasil enkripsi harus di encode dengan base64.\
       Hal ini dikarenakan web browser tidak dapat membaca karakter-karakter\
       ASCII dalam bentuk simbol-simbol */
    $buffer = $fileplain;
    $encrypted = mcrypt_generic($td, $buffer);
    $encrypted1 = base64_encode($iv) . ";" . base64_encode($encrypted);
    $encrypted2 = base64_encode($encrypted1);
    $filecipher = $encrypted2;
    /* Menghentikan proses enkripsi dan menutup modul */
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);
    return $filecipher;
}
開發者ID:kartikads,項目名稱:ch,代碼行數:25,代碼來源:mcrypt_function.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,代碼來源:albums.php

示例3: decrypt

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

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

示例5: phpFreaksCrypto

 function phpFreaksCrypto($key = 'a843l?nv89rjfd}O(jdnsleken0', $iv = false, $algorithm = 'tripledes', $mode = 'ecb')
 {
     if (extension_loaded('mcrypt') === FALSE) {
         //$prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
         //dl($prefix . 'mcrypt.' . PHP_SHLIB_SUFFIX) or die('The Mcrypt module could not be loaded.');
         die('The Mcrypt module is not loaded and is required.');
     }
     if ($mode != 'ecb' && $iv === false) {
         /*
           the iv must remain the same from encryption to decryption and is usually
           passed into the encrypted string in some form, but not always.
         */
         die('In order to use encryption modes other then ecb, you must specify a unique and consistent initialization vector.');
     }
     // set mcrypt mode and cipher
     $this->td = mcrypt_module_open($algorithm, '', $mode, '');
     // Unix has better pseudo random number generator then mcrypt, so if it is available lets use it!
     //$random_seed = strstr(PHP_OS, "WIN") ? MCRYPT_RAND : MCRYPT_DEV_RANDOM;
     $random_seed = MCRYPT_RAND;
     // if initialization vector set in constructor use it else, generate from random seed
     $iv = $iv === false ? mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), $random_seed) : substr($iv, 0, mcrypt_enc_get_iv_size($this->td));
     // get the expected key size based on mode and cipher
     $expected_key_size = mcrypt_enc_get_key_size($this->td);
     // we dont need to know the real key, we just need to be able to confirm a hashed version
     $key = substr(md5($key), 0, $expected_key_size);
     // initialize mcrypt library with mode/cipher, encryption key, and random initialization vector
     mcrypt_generic_init($this->td, $key, $iv);
 }
開發者ID:numericOverflow,項目名稱:phppickem,代碼行數:28,代碼來源:crypto.php

示例6: decrypt

 /**
  * 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);
 }
開發者ID:mrjulio,項目名稱:spartan-php,代碼行數:14,代碼來源:Crypt.php

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

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

示例9: decrypt

 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;
 }
開發者ID:adncentral,項目名稱:mapi-geoCMS,代碼行數:29,代碼來源:mlib.crypt.php

示例10: encrypt

 public function encrypt($string)
 {
     mcrypt_generic_init($this->cipher, $this->key, $this->iv);
     $cipherText = mcrypt_generic($this->cipher, $string);
     mcrypt_generic_deinit($this->cipher);
     return $cipherText;
 }
開發者ID:AmineCherrai,項目名稱:rostanvo,代碼行數:7,代碼來源:AesCbcMcrypt.class.php

示例11: decrypt

 /**
  * Decryption of data
  *
  * @param string      $data	Data to be decrypted
  * @param bool|string $key	Key, if not specified - system key will be used
  *
  * @return bool|mixed
  */
 function decrypt($data, $key = false)
 {
     if (!$this->encrypt_support) {
         return $data;
     }
     if (!is_resource($this->td)) {
         $this->td = mcrypt_module_open(MCRYPT_BLOWFISH, '', 'cbc', '');
         $this->key = mb_substr($this->key, 0, mcrypt_enc_get_key_size($this->td));
         $this->iv = mb_substr(md5($this->iv), 0, mcrypt_enc_get_iv_size($this->td));
     }
     if ($key === false) {
         $key = $this->key;
     } else {
         $key = mb_substr(md5($this->key) . md5($key), 0, mcrypt_enc_get_key_size($this->td));
     }
     mcrypt_generic_init($this->td, $key, $this->iv);
     errors_off();
     $decrypted = @unserialize(mdecrypt_generic($this->td, $data));
     errors_on();
     mcrypt_generic_deinit($this->td);
     if (is_array($decrypted) && $decrypted['key'] == $key) {
         return $decrypted['data'];
     } else {
         return false;
     }
 }
開發者ID:hypnomez,項目名稱:opir.org,代碼行數:34,代碼來源:Encryption.php

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

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

示例14: computeSign

 public function computeSign($sharedSecret)
 {
     if (!$this->isValid) {
         throw new Exception(__METHOD__ . ": Message was not validated.");
     }
     try {
         // ak mame zadany shared secret v hexa tvare tak ho prevedieme na 32 bytovy string
         if (strlen($sharedSecret) == 64) {
             $sharedSecret = pack('H*', $sharedSecret);
         }
         $base = $this->GetSignatureBase();
         $bytesHash = sha1($base, TRUE);
         // vezmeme prvych 16 bytov
         $bytesHash = substr($bytesHash, 0, 16);
         $aes = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($aes), MCRYPT_RAND);
         mcrypt_generic_init($aes, $sharedSecret, $iv);
         $bytesSign = mcrypt_generic($aes, $bytesHash);
         mcrypt_generic_deinit($aes);
         mcrypt_module_close($aes);
         $sign = strtoupper(bin2hex($bytesSign));
     } catch (Exception $e) {
         return FALSE;
     }
     return $sign;
 }
開發者ID:martinstrycek,項目名稱:php-payments,代碼行數:26,代碼來源:EPaymentAes256SignedMessage.class.php

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


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