• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP mcrypt_generic函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中mcrypt_generic函数的典型用法代码示例。如果您正苦于以下问题:PHP mcrypt_generic函数的具体用法?PHP mcrypt_generic怎么用?PHP mcrypt_generic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mcrypt_generic函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: _encryptRijndael256

 /**
  * Encrypt and return a string using the Rijndael 256 cypher
  * @param string $str String to encrypt
  * @param string $key Key to encrypt the string
  * @param string $iv Initialisation vector
  * @return string
  */
 public static function _encryptRijndael256($str, $key, $iv = FALSE)
 {
     // If the string is empty
     if (empty($str)) {
         return '';
     }
     // Open the cypher
     $cypher = mcrypt_module_open('rijndael-256', '', 'ofb', '');
     // Create the IV if there is none
     if ($iv === FALSE) {
         $iv = self::_genRijndael256IV($cypher);
     }
     // Set Key
     $key = substr($key, 0, mcrypt_enc_get_key_size($cypher));
     // Initialise encryption
     mcrypt_generic_init($cypher, $key, $iv);
     // Encrypt String
     $encrypted = mcrypt_generic($cypher, $strString);
     // Terminate encryption hander
     mcrypt_generic_deinit($cypher);
     // Close Module
     mcrypt_module_close($cypher);
     // Return encrypted string
     return $encrypted;
 }
开发者ID:andyburton,项目名称:sonic-framework,代码行数:32,代码来源:Crypt.php


示例2: encrypt

 /**
  */
 public function encrypt($text)
 {
     mcrypt_generic_init($this->_mcrypt, $this->key, empty($this->iv) ? str_repeat('0', Horde_Crypt_Blowfish::IV_LENGTH) : $this->iv);
     $out = mcrypt_generic($this->_mcrypt, $this->_pad($text));
     mcrypt_generic_deinit($this->_mcrypt);
     return $out;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:9,代码来源:Mcrypt.php


示例3: tripleDESEncrypt1

 function tripleDESEncrypt1($src, $key)
 {
     if ($src == NULL) {
         return NULL;
     }
     $iv = $this->my_mcrypt_create_iv();
     /* Open module, and create IV */
     $td = mcrypt_module_open(MCRYPT_3DES, '', 'cbc', '');
     if ($key == NULL) {
         $key = "";
     }
     $key = substr($key, 0, mcrypt_enc_get_key_size($td));
     /* Initialize encryption handle */
     if (mcrypt_generic_init($td, $key, $iv) != -1) {
         /* Encrypt data */
         $encryptedData = mcrypt_generic($td, $src);
         $iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_CBC);
         $encryptedData = chr($iv_size) . $iv . $encryptedData;
         mcrypt_generic_deinit($td);
         //echo "src is:" . $src. "<br>\n";
         //echo "iv is :" .bin2hex($iv)."<br>\n";
         //echo "key is :" .bin2hex($key)."<br>\n";
     } else {
         $encryptedData = null;
     }
     mcrypt_module_close($td);
     return $encryptedData;
 }
开发者ID:zw1003855799,项目名称:SE-Service-Exchange,代码行数:28,代码来源:clsJAccount.php


示例4: encrypt

 public static function encrypt($keyString, $value)
 {
     $origKey = $keyString;
     if (strlen($keyString) > 32) {
         $keyString = substr($keyString, 0, 32);
     }
     if (strlen($keyString) < 32) {
         $keyString = str_pad($keyString, 32, 'X');
     }
     $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
     $iv = TPSecurityUtils::genRandomString(16);
     if (mcrypt_generic_init($cipher, $keyString, $iv) != -1) {
         $blockSize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
         $padding = $blockSize - strlen($value) % $blockSize;
         $value .= str_repeat(chr($padding), $padding);
         // PHP pads with NULL bytes if $value is not a multiple of the block size..
         $cipherText = mcrypt_generic($cipher, $value);
         mcrypt_generic_deinit($cipher);
         mcrypt_module_close($cipher);
         $safe = TPSecurityUtils::urlensafe($cipherText);
         return $safe . TPSecurityUtils::DELIM . TPSecurityUtils::hashHmacSha256($origKey, $safe);
     }
     $safe = TPSecurityUtils::urlensafe($value);
     return $safe . TPSecurityUtils::DELIM . TPSecurityUtils::hashHmacSha256($origKey, $safe);
 }
开发者ID:voodoologic,项目名称:reboot,代码行数:25,代码来源:TPSecurityUtils.php


示例5: encrypt

 /**
  * Encrypt
  * 
  * @return mixed string|null
  * @param object $value
  */
 public function encrypt($value)
 {
     if (empty($value)) {
         return $value;
     }
     return base64_encode(mcrypt_generic($this->_handler, (string) $value));
 }
开发者ID:baisoo,项目名称:axiscommerce,代码行数:13,代码来源:MCrypt.php


示例6: encrypt

 /**
  * Ritorna la string codificata.
  * Se il costruttore ha fallito nell'inizializzazione dell'algoritmo di cifratura, la stringa viene
  * restituita in chiaro; altrimenti la codifica consiste nella cifratura con l'algoritmo scelto.
  * 
  * @param string $str Se non viene passata nessuna stringa ritorna una stringa vuota.
  * @return string
  */
 public function encrypt($str)
 {
     try {
         $str = filter_var($str, FILTER_SANITIZE_STRING);
         if (empty($str)) {
             throw new InvalidArgumentException('Empty or not valid string as agrument', E_USER_NOTICE);
         }
         if (!isset($this->_cipher)) {
             throw new UnexpectedValueException('Cypher error', E_USER_WARNING);
         }
         if (false === ($iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->_cipher), MCRYPT_RAND))) {
             throw new UnexpectedValueException('Cannot initialize vector IV', E_USER_WARNING);
         }
         $s = mcrypt_generic_init($this->_cipher, $this->_key, $iv);
         if (0 > $s || false === $s) {
             throw new exceptions('Encrypt failure', E_USER_WARNING);
         }
         $enc = mcrypt_generic($this->_cipher, $str);
         mcrypt_generic_deinit($this->_cipher);
         return $enc;
     } catch (Exception $e) {
         debug::exception($e);
         return $str;
     }
 }
开发者ID:GGallery,项目名称:MDWEBTV-new,代码行数:33,代码来源:crypto.class.php


示例7: enkripsi

 public function enkripsi($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:datadigicore,项目名称:admin_cat,代码行数:25,代码来源:utilityCode.php


示例8: aes128_encode

function aes128_encode($data, $mode)
{
    switch ($mode) {
        case "ECB":
        case "CBC":
            if ($mode === "ECB") {
                $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
            } else {
                $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
            }
            $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($cipher), MCRYPT_RAND);
            $key = substr('naveen', 0, mcrypt_enc_get_key_size($cipher));
            if (mcrypt_generic_init($cipher, $key, $iv) != 1) {
                $cipherData = mcrypt_generic($cipher, $data);
                mcrypt_generic_deinit($cipher);
                mcrypt_module_close($cipher);
                if ($mode === "ECB") {
                    $sanitizedCipherData = trim(base64_encode($cipherData));
                } else {
                    $sanitizedCipherData = trim(base64_encode($iv) . "_" . base64_encode($cipherData));
                }
                return $sanitizedCipherData;
            } else {
                return false;
            }
            break;
        default:
            return false;
            break;
    }
}
开发者ID:neevan1e,项目名称:Done,代码行数:31,代码来源:encryption_function.php


示例9: encrypt

 static function encrypt($input, $base64 = true)
 {
     if (!$input || !strlen($input) > 0) {
         return null;
     }
     if (!($td = mcrypt_module_open('rijndael-256', '', 'ctr', ''))) {
         return null;
     }
     if (!($iv = mcrypt_create_iv(32, MCRYPT_RAND))) {
         return null;
     }
     $content = serialize($input);
     if (mcrypt_generic_init($td, MSettings::$c_key, $iv) !== 0) {
         return null;
     }
     $content = mcrypt_generic($td, $content);
     $content = $iv . $content;
     $mac = self::pbkdf2($content, MSettings::$c_key, 1000, 32);
     $content .= $mac;
     mcrypt_generic_deinit($td);
     mcrypt_module_close($td);
     if ($base64) {
         $content = base64_encode($content);
     }
     return $content;
 }
开发者ID:adncentral,项目名称:mapi-geoCMS,代码行数:26,代码来源:mlib.crypt.php


示例10: encrypt

 /**
  * Encrypt data
  *
  * This method will encrypt data using a given key, vector, and cipher.
  * By default, this will encrypt data using the RIJNDAEL/AES 256 bit cipher. You
  * may override the default cipher and cipher mode by passing your own desired
  * cipher and cipher mode as the final key-value array argument.
  *
  * @param  string $data     The unencrypted data
  * @param  string $key      The encryption key
  * @param  string $iv       The encryption initialization vector
  * @param  array  $settings Optional key-value array with custom algorithm and mode
  * @return string
  */
 public static function encrypt($data, $key, $iv, $settings = array())
 {
     if ($data === '' || !extension_loaded('mcrypt')) {
         return $data;
     }
     //Merge settings with defaults
     $defaults = array('algorithm' => MCRYPT_RIJNDAEL_256, 'mode' => MCRYPT_MODE_CBC);
     $settings = array_merge($defaults, $settings);
     //Get module
     $module = mcrypt_module_open($settings['algorithm'], '', $settings['mode'], '');
     //Validate IV
     $ivSize = mcrypt_enc_get_iv_size($module);
     if (strlen($iv) > $ivSize) {
         $iv = substr($iv, 0, $ivSize);
     }
     //Validate key
     $keySize = mcrypt_enc_get_key_size($module);
     if (strlen($key) > $keySize) {
         $key = substr($key, 0, $keySize);
     }
     //Encrypt value
     mcrypt_generic_init($module, $key, $iv);
     $res = @mcrypt_generic($module, $data);
     mcrypt_generic_deinit($module);
     return $res;
 }
开发者ID:ferdinandmartin,项目名称:pulse,代码行数:40,代码来源:Util.php


示例11: set

 /**
  * Store an encrypted cookie
  *
  * @param string $cookieName
  * @param mixed  $cookieValue
  * @param int    $expiry default stores just for the browser session
  */
 public static function set($cookieName, $cookieValue, $expiry = 0)
 {
     if (isset($_COOKIE['synsec'])) {
         $synsec = $_COOKIE['synsec'];
     } else {
         $synsec = Tools::randomString('12');
     }
     if ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') && (!isset($_SERVER['HTTP_X_FORWARDED_PROTO']) || $_SERVER['HTTP_X_FORWARDED_PROTO'] != 'https')) {
         $ssl = false;
     } else {
         $ssl = true;
     }
     setcookie('synsec', $synsec, time() + 60 * 60 * 24 * 30, '/', $_SERVER['HTTP_HOST'], $ssl, true);
     $synsec .= 'synErgy' . self::$token;
     /* Open the cipher */
     $td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
     /* Create the IV and determine the keysize length, use MCRYPT_RAND
      * on Windows instead */
     $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
     $ks = mcrypt_enc_get_key_size($td);
     /* Create key */
     $key = substr(md5($synsec), 0, $ks);
     /* Intialize encryption */
     mcrypt_generic_init($td, $key, $iv);
     /* Encrypt data */
     $encrypted = mcrypt_generic($td, serialize($cookieValue));
     # Store our secure cookie
     setcookie($cookieName, trim(base64_encode($iv . '|' . $encrypted)), $expiry, '/', $_SERVER['HTTP_HOST'], $ssl, true);
     /* Terminate encryption handler */
     mcrypt_generic_deinit($td);
 }
开发者ID:chrisnoden,项目名称:synergy,代码行数:38,代码来源:SecureCookie.php


示例12: encrypt

 private function encrypt($key, $data, $cipher = MCRYPT_3DES, $hash = 'sha256')
 {
     $td = mcrypt_module_open($cipher, '', MCRYPT_MODE_ECB, '');
     if ($td === false) {
         return false;
     }
     $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_URANDOM);
     if ($iv === false) {
         return false;
     }
     $ks = mcrypt_enc_get_key_size($td);
     switch ($hash) {
         case 'md5':
             $key = substr($this->md5($key), 0, $ks);
         case 'sha256':
             $key = substr($this->sha256($key), 0, $ks);
         case 'sha512':
             $key = substr($this->sha512($key), 0, $ks);
         case 'none':
         default:
             $key = substr($key, 0, $ks);
     }
     mcrypt_generic_init($td, $key, $iv);
     $ret = mcrypt_generic($td, $data);
     mcrypt_generic_deinit($td);
     mcrypt_module_close($td);
     return $iv . $ret;
 }
开发者ID:appdeck,项目名称:sampa,代码行数:28,代码来源:Secure.php


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


示例14: mcrypt

 /**
  * @param string $string
  * @return string
  */
 protected function mcrypt($string)
 {
     $this->encryptInit();
     $encrypted = mcrypt_generic($this->getEncryptionDescriptor(), $string);
     $this->encryptDeinit();
     return $encrypted;
 }
开发者ID:testinaweb,项目名称:dynamic-crypto,代码行数:11,代码来源:DynamicEncrypter.php


示例15: encrypt

 /**
  * 对明文进行加密
  * @param string $text 需要加密的明文
  * @return string 加密后的密文
  */
 public function encrypt($text, $appid)
 {
     try {
         //获得16位随机字符串,填充到明文之前
         $random = $this->getRandomStr();
         $text = $random . pack("N", strlen($text)) . $text . $appid;
         // 网络字节序
         $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
         $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
         $iv = substr($this->key, 0, 16);
         //使用自定义的填充方式对明文进行补位填充
         $pkc_encoder = new Pkcs7Encoder();
         $text = $pkc_encoder->encode($text);
         mcrypt_generic_init($module, $this->key, $iv);
         //加密
         $encrypted = mcrypt_generic($module, $text);
         mcrypt_generic_deinit($module);
         mcrypt_module_close($module);
         //使用BASE64对加密后的字符串进行编码
         return base64_encode($encrypted);
     } catch (Exception $e) {
         @error_log('Encrypt AES Error: ' . $e->getMessage(), 0);
         return FALSE;
     }
 }
开发者ID:PunkAvail,项目名称:ThinkWechat,代码行数:30,代码来源:Prpcrypt.class.php


示例16: ssl_encode

 function ssl_encode($data, $key = '')
 {
     // Use the Encrypt.php function get_key to encode the data.
     $key = $this->get_key($key);
     // Set a random salt
     $salt = substr(md5(mt_rand(), true), 8);
     $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
     $pad = $block - strlen($data) % $block;
     $data = $data . str_repeat(chr($pad), $pad);
     // Setup encryption parameters
     $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_CBC, "");
     $key_len = mcrypt_enc_get_key_size($td);
     $iv_len = mcrypt_enc_get_iv_size($td);
     $total_len = $key_len + $iv_len;
     $salted = '';
     $dx = '';
     // Salt the key and iv
     while (strlen($salted) < $total_len) {
         $dx = md5($dx . $key . $salt, true);
         $salted .= $dx;
     }
     $key = substr($salted, 0, $key_len);
     $iv = substr($salted, $key_len, $iv_len);
     mcrypt_generic_init($td, $key, $iv);
     $encrypted_data = mcrypt_generic($td, $data);
     mcrypt_generic_deinit($td);
     mcrypt_module_close($td);
     return chunk_split(base64_encode('Salted__' . $salt . $encrypted_data), 32, "\n");
 }
开发者ID:kaptk2,项目名称:AirKey,代码行数:29,代码来源:MY_Encrypt.php


示例17: encode

 /**
  * 对字符串进行加密
  *
  * @param string $string 要加密的字符串
  *
  * @return string
  */
 public function encode($string)
 {
     mcrypt_generic_init($this->td, $this->key, $this->iv);
     $data = base64_encode(mcrypt_generic($this->td, $string));
     mcrypt_generic_deinit($this->td);
     return $data;
 }
开发者ID:3032441712,项目名称:person,代码行数:14,代码来源:Data.php


示例18: encrypt

 /** Encryption Procedure
  *  @param mixed msg message/data
  *  @param string k encryption key
  *  @param bool base64 base64 encode result
  *
  *  @return string iv+ciphertext+mac or
  * boolean false on error
  */
 public function encrypt($msg, $base64 = false)
 {
     $k = $this->key;
     # open cipher module (do not change cipher/mode)
     if (!($td = mcrypt_module_open('rijndael-128', '', 'ctr', ''))) {
         return false;
     }
     $iv = mcrypt_create_iv(16, MCRYPT_RAND);
     # create iv
     if (mcrypt_generic_init($td, $k, $iv) !== 0) {
         # initialize buffers
         return false;
     }
     $msg = mcrypt_generic($td, $msg);
     # encrypt
     $msg = $iv . $msg;
     # prepend iv
     $mac = $this->pbkdf2($msg, $k, 1000, 16);
     # create mac
     $msg .= $mac;
     # append mac
     mcrypt_generic_deinit($td);
     # clear buffers
     mcrypt_module_close($td);
     # close cipher module
     if ($base64) {
         $msg = base64_encode($msg);
         # base64 encode?
     }
     return $msg;
     # return iv+ciphertext+mac
 }
开发者ID:corneltek,项目名称:phifty,代码行数:40,代码来源:AesCryptorServiceProvider.php


示例19: encrypt

 /**
  * Encrypt
  *
  * @param string  $data  Data to encrypt
  *
  * @return string
  */
 public function encrypt($data)
 {
     mcrypt_generic_init($this->module, $this->key, $this->iv);
     $encrypted = mcrypt_generic($this->module, $data);
     mcrypt_generic_deinit($this->module);
     return $encrypted;
 }
开发者ID:mrjulio,项目名称:spartan-php,代码行数:14,代码来源:Crypt.php


示例20: encrypt

 public function encrypt($input, $is_id = false)
 {
     static $_map = array();
     if ($is_id) {
         $input = base_convert($input, 10, 36);
     }
     $hashkey = md5($input . $this->key);
     if (isset($_map[$hashkey])) {
         return $_map[$hashkey];
     }
     $size = mcrypt_get_block_size(MCRYPT_3DES, 'ecb');
     $input = $this->pkcs5_pad($input, $size);
     $key = str_pad($this->key, 24, '0');
     $td = mcrypt_module_open(MCRYPT_3DES, '', 'ecb', '');
     $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
     @mcrypt_generic_init($td, $key, $iv);
     $data = mcrypt_generic($td, $input);
     mcrypt_generic_deinit($td);
     mcrypt_module_close($td);
     $tmp = '';
     if ($is_id) {
         $len = strlen($data);
         for ($i = 0; $i < $len; $i++) {
             $tmp = $tmp . str_pad(dechex(ord($data[$i])), 2, 0, STR_PAD_LEFT);
         }
         $_map[$hashkey] = $tmp;
         return $tmp;
     }
     $_map[$hashkey] = $tmp;
     $data = base64_encode($data);
     return $data;
 }
开发者ID:lanma121,项目名称:superPrize,代码行数:32,代码来源:Encty.php



注:本文中的mcrypt_generic函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP mcrypt_generic_deinit函数代码示例发布时间:2022-05-15
下一篇:
PHP mcrypt_encrypt函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap