最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php blowfish加密解密算法

 更新時間:2016年07月02日 13:47:30   投稿:lijiao  
這篇文章主要為大家詳細介紹了php blowfish加密解密算法的相關資料,感興趣的朋友可以參考一下

PHP Blowfish 算法的加密解密,供大家參考,具體內容如下

<?php
 
/**
 * php blowfish 算法
 * Class blowfish
 */
class blowfish{
 /**
  * blowfish + cbc模式 + pkcs5補碼 加密
  * @param string $str 需要加密的數據
  * @return string 加密后base64加密的數據
  */
 public function blowfish_cbc_pkcs5_encrypt($str)
 {
  $cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
 
  //pkcs5補碼
  $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 解密 去補碼
  * @param string $str 加密的數據
  * @return string 解密的數據
  */
 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 
 
?>

以上就是本文的全部內容,希望對大家學習php程序設計有所幫助。

相關文章

  • php debug 安裝技巧

    php debug 安裝技巧

    軟件開發(fā)的斷點調試是必不可少,這里介紹ubuntu10.04中eclipse工具中php的調試配置。
    2011-04-04
  • PHP定時任務獲取微信access_token的方法

    PHP定時任務獲取微信access_token的方法

    這篇文章主要介紹了PHP定時任務獲取微信access_token的方法,涉及php基于curl動態(tài)獲取access_token及CentOS下crontab設置計劃任務的相關操作技巧,需要的朋友可以參考下
    2016-10-10
  • php HTML無刷新提交表單

    php HTML無刷新提交表單

    這篇文章主要介紹了php HTML無刷新提交表單,本文介紹了兩種無刷新提交表單的方法,感興趣的小伙伴們可以參考一下
    2016-04-04
  • php的4種常用運行方式詳解

    php的4種常用運行方式詳解

    這篇文章主要介紹了php的4種常用運行方式,CGI、FastCGI、APACHE2HANDLER和CLI,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • CentOS系統(tǒng)中PHP安裝擴展的方式匯總

    CentOS系統(tǒng)中PHP安裝擴展的方式匯總

    本文給大家匯總介紹了CentOS系統(tǒng)中PHP安裝拓展的方式,主要有 包管理式 的 yum 安裝、pecl 安裝,以及 源碼編譯安裝??偨Y的非常全面,推薦給大家。
    2017-04-04
  • php頁面緩存ob系列函數介紹

    php頁面緩存ob系列函數介紹

    這幾天接觸了phpcms的頁面緩存,有些感觸。其好處就不多說了,它一般是用在數據庫查詢較多的頁面中,對于插入修改刪除的頁面就不大合適了
    2012-10-10
  • PHP編程基本語法快速入門手冊

    PHP編程基本語法快速入門手冊

    這篇文章主要介紹了PHP編程基本語法快速入門的一些知識,包括PHP的數組與循環(huán)語句等基礎知識點,需要的朋友可以參考下
    2016-01-01
  • PHP接入Apple對access_token/identityToken進行JWT驗證流程詳解

    PHP接入Apple對access_token/identityToken進行JWT驗證流程詳解

    JWT(JSON Web Token)是為了在網絡應用環(huán)境間傳遞聲明而執(zhí)行的一種基于JSON的開放標準。本文將為大家介紹PHP如何實現JWT登錄鑒權,需要的可以參考一下
    2022-09-09
  • PHP基于自定義類隨機生成姓名的方法示例

    PHP基于自定義類隨機生成姓名的方法示例

    這篇文章主要介紹了PHP基于自定義類隨機生成姓名的方法,結合實例形式分析了php基于數組與字符串的隨機數操作生成姓名的相關實現技巧,需要的朋友可以參考下
    2017-08-08
  • Ajax+Jpgraph實現的動態(tài)折線圖功能示例

    Ajax+Jpgraph實現的動態(tài)折線圖功能示例

    這篇文章主要介紹了Ajax+Jpgraph實現的動態(tài)折線圖功能,結合實例形式分析了ajax結合jpgraph.php類庫繪制動態(tài)折線圖的相關操作技巧,需要的朋友可以參考下
    2019-02-02

最新評論

申扎县| 噶尔县| 班玛县| 无棣县| 靖宇县| 高州市| 旬邑县| 贞丰县| 保山市| 沙河市| 西青区| 安龙县| 揭西县| 额敏县| 丘北县| 比如县| 昌邑市| 奉化市| 阿尔山市| 新民市| 阳泉市| 平谷区| 宜兰县| 西畴县| 固安县| 含山县| 新和县| 驻马店市| 临西县| 十堰市| 吉隆县| 高阳县| 屯昌县| 方正县| 阳新县| 百色市| 堆龙德庆县| 海门市| 嘉禾县| 巩义市| 常宁市|