当前位置: 首页>>代码示例>>PHP>>正文


PHP mcrypt_get_block_size函数代码示例

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


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

示例1: encrypt

 static function encrypt($str, $key)
 {
     $size = mcrypt_get_block_size(MCRYPT_DES, MCRYPT_MODE_CBC);
     $str = self::pkcs5Pad($str, $size);
     $bin = mcrypt_cbc(MCRYPT_DES, $key, $str, MCRYPT_ENCRYPT, $key);
     return bin2hex($bin);
 }
开发者ID:qiaopingxie,项目名称:eLong-OpenAPI-PHP-demo,代码行数:7,代码来源:Xcrypt.php

示例2: decrypt

function decrypt($str, $key)
{
    $str = mcrypt_decrypt(MCRYPT_DES, $key, base64_decode($str), MCRYPT_MODE_ECB);
    $block = mcrypt_get_block_size('des', 'ecb');
    $pad = ord($str[($len = strlen($str)) - 1]);
    return substr($str, 0, strlen($str) - $pad);
}
开发者ID:remobile,项目名称:react-native-des,代码行数:7,代码来源:Des.php

示例3: PaddingPKCS7

 private function PaddingPKCS7($data)
 {
     $block_size = mcrypt_get_block_size('tripledes', 'cbc');
     $padding_char = $block_size - strlen($data) % $block_size;
     $data .= str_repeat(chr($padding_char), $padding_char);
     return $data;
 }
开发者ID:tianyong90,项目名称:lucksdk,代码行数:7,代码来源:Encryptor.php

示例4: 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);
         //print(base64_encode($encrypted));
         //使用BASE64对加密后的字符串进行编码
         return array(ErrorCode::$OK, base64_encode($encrypted));
     } catch (Exception $e) {
         //print $e;
         return array(ErrorCode::$EncryptAESError, NULL);
     }
 }
开发者ID:sosyuki,项目名称:wechat,代码行数:31,代码来源:Prpcrypt.php

示例5: __construct

 public function __construct()
 {
     parent::__construct();
     $this->iv = mcrypt_create_iv(mcrypt_get_block_size(MCRYPT_TripleDES, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
     $this->key = 'LeeS1bae';
     $this->delimiter = '%%';
 }
开发者ID:roycocup,项目名称:enclothed,代码行数:7,代码来源:gifts.php

示例6: encrypt

 function encrypt($str)
 {
     //加密,返回大写十六进制字符串
     $size = mcrypt_get_block_size(MCRYPT_DES, MCRYPT_MODE_CBC);
     $str = $this->pkcs5Pad($str, $size);
     return strtoupper(bin2hex(mcrypt_cbc(MCRYPT_DES, $this->key, $str, MCRYPT_ENCRYPT, $this->iv)));
 }
开发者ID:samuelcs,项目名称:videonewsweb,代码行数:7,代码来源:des.php

示例7: encrypt

 function encrypt($str)
 {
     $size = mcrypt_get_block_size(MCRYPT_DES, MCRYPT_MODE_CBC);
     $str = $this->pkcs5Pad($str, $size);
     $data = mcrypt_cbc(MCRYPT_DES, $this->key, $str, MCRYPT_ENCRYPT, $this->iv);
     return base64_encode($data);
 }
开发者ID:justinyaoqi,项目名称:qyhr,代码行数:7,代码来源:desjava.class.php

示例8: encrypt

 private static function encrypt($str)
 {
     $block = mcrypt_get_block_size('des', 'ecb');
     $pad = $block - strlen($str) % $block;
     $str .= str_repeat(chr($pad), $pad);
     return mcrypt_encrypt(MCRYPT_DES, self::PRIVATE_KEY, $str, MCRYPT_MODE_ECB);
 }
开发者ID:Rongya,项目名称:TeamToy-Plugins,代码行数:7,代码来源:OpenId.php

示例9: get_prefix_len

function get_prefix_len($key)
{
    $mult = 3;
    $bsize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
    $enc = encrypt_aes_ecb(str_repeat('A', $bsize * $mult), $key);
    $blocks = str_split($enc, $bsize);
    $index = $prefix_len = 0;
    for ($i = 1, $c = count($blocks); $i < $c; $i++) {
        if ($blocks[$i] == $blocks[$i - 1]) {
            $index = $i;
        } else {
            if ($index != 0) {
                break;
            }
        }
    }
    for ($i = $bsize * $mult - 1; $i >= 0; $i--, $prefix_len++) {
        $enc = encrypt_aes_ecb(str_repeat('A', $i), $key);
        $blocks = str_split($enc, $bsize);
        if ($blocks[$index] != $blocks[$index - 1]) {
            $prefix_len += $bsize * ($index - $mult + 1);
            break;
        }
    }
    return $prefix_len;
}
开发者ID:jjc224,项目名称:Matasano,代码行数:26,代码来源:14.php

示例10: PaddingPKCS7

 function PaddingPKCS7($data)
 {
     $block_size = mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC);
     $padding_char = $block_size - strlen($data) % $block_size;
     $data .= str_repeat(chr($padding_char), $padding_char);
     return $data;
 }
开发者ID:asmenglei,项目名称:lanxiao,代码行数:7,代码来源:Crypt3des.php

示例11: pad_pkcs7

function pad_pkcs7($string)
{
    $bsize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
    $padding = $bsize - strlen($string) % $bsize;
    $string .= str_repeat(chr($padding), $padding);
    return $string;
}
开发者ID:jjc224,项目名称:Matasano,代码行数:7,代码来源:16.php

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

示例13: encryptMsg

 public function encryptMsg($text)
 {
     $token = $this->account['token'];
     $encodingaeskey = $this->account['encodingaeskey'];
     $appid = $this->account['key'];
     $key = base64_decode($encodingaeskey . '=');
     $text = random(16) . 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($key, 0, 16);
     $block_size = 32;
     $text_length = strlen($text);
     $amount_to_pad = $block_size - $text_length % $block_size;
     if ($amount_to_pad == 0) {
         $amount_to_pad = $block_size;
     }
     $pad_chr = chr($amount_to_pad);
     $tmp = '';
     for ($index = 0; $index < $amount_to_pad; $index++) {
         $tmp .= $pad_chr;
     }
     $text = $text . $tmp;
     mcrypt_generic_init($module, $key, $iv);
     $encrypted = mcrypt_generic($module, $text);
     mcrypt_generic_deinit($module);
     mcrypt_module_close($module);
     $encrypt_msg = base64_encode($encrypted);
     $signature = $this->buildSignature($encrypt_msg);
     return array($signature, $encrypt_msg);
 }
开发者ID:7demo,项目名称:we7,代码行数:30,代码来源:weixin.account.class.php

示例14: _getComplete

 /**
  * _getComplete
  *
  * method is prepare complete xml data call from callback url page.
  *
  * @param Dahius_VirtualPos_Request $request
  * @return string 
  */
 protected function _getComplete($request)
 {
     $response = new Dahius_VirtualPos_Response();
     $response->createdOn = time();
     $response->createdBy = $this->_name;
     // Check 3D Values
     $merchantPack = $request->threeDResponse["MerchantPacket"];
     $bankPack = $request->threeDResponse["BankPacket"];
     $sign = $request->threeDResponse["Sign"];
     $hash = strtoupper(md5($merchantPack . $bankPack . $this->_parameters->getPath("merchant_key")));
     if (strcmp($hash, $sign) != 0) {
         $response->code = -4;
         $response->message = "Package Not Matched";
         return $response;
     }
     // Get MD Status...
     $block = mcrypt_get_block_size(MCRYPT_TripleDES, MCRYPT_MODE_CBC);
     $tdes = mcrypt_module_open(MCRYPT_TripleDES, '', MCRYPT_MODE_CBC, '');
     $key_size = mcrypt_enc_get_key_size($tdes);
     $merchant_info = $this->_deCrypt($merchantPack, $this->_parameters->getPath("merchant_key"), $block, $tdes, $key_size);
     mcrypt_generic_deinit($tdes);
     mcrypt_module_close($tdes);
     list($mid, $tid, $amount, $instant, $xid, $tp, $tpo, $webURL, $ip, $port, $txStatus, $mdStatus, $errMsg, $transactionTime, $currency) = explode(";", $merchant_info);
     if (!in_array($mdStatus, $this->_parameters->getPath("valid_md_status"))) {
         $response->code = -3;
         $response->message = "mdStatus({$request->threeDResponse["mdStatus"]}) Not Valid";
         return $response;
     }
     $xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-9\"?>\n                <posnetRequest>\n                    <mid>{$this->_parameters->getPath("mid")}</mid>\n                    <tid>{$this->_parameters->getPath("tid")}</tid>\n                    <username>{$this->_parameters->getPath("username")}</username>\n                    <password>{$this->_parameters->getPath("password")}</password>\n                    <oosTran>\n                        <bank>{$bankPack}</bank>\n                        <wpAmount>0</wpAmount>\n                    </oosTran>\n                </posnetRequest>";
     return "xmldata={$xml}";
 }
开发者ID:hisef,项目名称:vpos4php,代码行数:39,代码来源:Posnet.php

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


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