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

php blowfish加密解密算法

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

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

<?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ì)有所幫助。

相關(guān)文章

  • php debug 安裝技巧

    php debug 安裝技巧

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

    PHP定時(shí)任務(wù)獲取微信access_token的方法

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

    php HTML無刷新提交表單

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

    php的4種常用運(yùn)行方式詳解

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

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

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

    php頁(yè)面緩存ob系列函數(shù)介紹

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

    PHP編程基本語(yǔ)法快速入門手冊(cè)

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

    PHP接入Apple對(duì)access_token/identityToken進(jìn)行JWT驗(yàn)證流程詳解

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

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

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

    Ajax+Jpgraph實(shí)現(xiàn)的動(dòng)態(tài)折線圖功能示例

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

最新評(píng)論

宿松县| 黔江区| 栖霞市| 亚东县| 陇西县| 新和县| 柘荣县| 渭南市| 新巴尔虎左旗| 大邑县| 亳州市| 射洪县| 涟水县| 淮阳县| 昆明市| 玛沁县| 乃东县| 旺苍县| 遂溪县| 东台市| 扎鲁特旗| 竹溪县| 武川县| 马山县| 绥棱县| 和田市| 石屏县| 延长县| 徐州市| 许昌县| 汉源县| 土默特右旗| 德格县| 雷波县| 中超| 台江县| 承德市| 扎赉特旗| 太湖县| 绍兴县| 西乡县|