茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    php blowfish加密解密算法
    來(lái)源:易賢網(wǎng) 閱讀:1346 次 日期:2016-08-15 15:34:55
    溫馨提示:易賢網(wǎng)小編為您整理了“php blowfish加密解密算法”,方便廣大網(wǎng)友查閱!

    這篇文章主要為大家詳細(xì)介紹了php blowfish加密解密算法的相關(guān)資料,感興趣的朋友可以參考一下

    <?php

    /**

     * php blowfish 算法

     * Class blowfish

     */

    class blowfish{

     /**

      * blowfish + cbc模式 + pkcs5補(bǔ)碼 加密

      * @param string $str 需要加密的數(shù)據(jù)

      * @return string 加密后base64加密的數(shù)據(jù)

      */

     public function blowfish_cbc_pkcs5_encrypt($str)

     {

      $cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');

      //pkcs5補(bǔ)碼

      $size = mcrypt_get_block_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);

      $str = $this->pkcs5_pad($str, $size);

      if (mcrypt_generic_init($cipher, $this->key, $this->iv) != -1)

      {

       $cipherText = mcrypt_generic($cipher, $str);

       mcrypt_generic_deinit($cipher);

       return base64_encode($cipherText);

      }

      mcrypt_module_close($cipher);

     }

     /**

      * blowfish + cbc模式 + pkcs5 解密 去補(bǔ)碼

      * @param string $str 加密的數(shù)據(jù)

      * @return string 解密的數(shù)據(jù)

      */

     public function blowfish_cbc_pkcs5_decrypt($str)

     {

      $cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');

      if (mcrypt_generic_init($cipher, $this->key, $this->iv) != -1)

      {

       $cipherText = mdecrypt_generic($cipher, base64_decode($str));

       mcrypt_generic_deinit($cipher);

       return $this->pkcs5_unpad($cipherText);

      }

      mcrypt_module_close($cipher);

     }

     private function pkcs5_pad($text, $blocksize){

      $pad = $blocksize - (strlen ( $text ) % $blocksize);

      return $text . str_repeat ( chr ( $pad ), $pad );

     }

     private function pkcs5_unpad($str){

      $pad = ord($str[($len = strlen($str)) - 1]);

      return substr($str, 0, strlen($str) - $pad);

     }

    }

    BlowFish加密算法在php的使用第二例

    <?php

     $cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');

     // The block-size of the Blowfish algorithm is 64-bits, therefore our IV

     // is always 8 bytes:

     $iv = '12345678';

     $key256 = '1234567890123456ABCDEFGHIJKLMNOP';

     $key128 = '1234567890123456';

     printf("iv: %s\n",bin2hex($iv));

     printf("key256: %s\n",bin2hex($key256));

     printf("key128: %s\n",bin2hex($key128));

     $cleartext = 'The quick brown fox jumped over the lazy dog';

     printf("clearText: %s\n\n",$cleartext);

     // Do 256-bit blowfish encryption:

     // The strengh of the encryption is determined by the length of the key

     // passed to mcrypt_generic_init

     if (mcrypt_generic_init($cipher, $key256, $iv) != -1)

     {

      // PHP pads with NULL bytes if $cleartext is not a multiple of the block size..

      $cipherText = mcrypt_generic($cipher,$cleartext );

      mcrypt_generic_deinit($cipher);

      // Display the result in hex.

      printf("256-bit blowfish encrypted:\n%s\n\n",bin2hex($cipherText));

     }

     // 128-bit blowfish encryption:

     if (mcrypt_generic_init($cipher, $key128, $iv) != -1)

     {

      // PHP pads with NULL bytes if $cleartext is not a multiple of the block size..

      $cipherText = mcrypt_generic($cipher,$cleartext );

      mcrypt_generic_deinit($cipher);

      // Display the result in hex.

      printf("128-bit blowfish encrypted:\n%s\n\n",bin2hex($cipherText));

     }

     // -------

     // Results

     // -------

     // You may use these as test vectors for testing your Blowfish implementations...

     // 

     // iv: 3132333435363738

     // key256: 313233343536373839303132333435364142434445464748494a4b4c4d4e4f50

     // key128: 31323334353637383930313233343536

     // clearText: The quick brown fox jumped over the lazy dog

     // 

     // 256-bit blowfish encrypted:

     // 276855ca6c0d60f7d9708210440c1072e05d078e733b34b4198d609dc2fcc2f0c30926cdef3b6d52baf6e345aa03f83e

     // 

     // 128-bit blowfish encrypted:

     // d2b5abb73208aea3790621d028afcc74d8dd65fb9ea8e666444a72523f5ecca60df79a424e2c714fa6efbafcc40bdca0 

    ?>

    以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:php blowfish加密解密算法
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報(bào)班

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)