亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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 用checkbox一次性刪除多條記錄的方法

    php 用checkbox一次性刪除多條記錄的方法

    一次性刪除多條記錄,對(duì)于比較多的信息,如果沒(méi)有批量刪除功能是非常麻煩的。這樣就方便多了。
    2010-02-02
  • 詳解php的socket通信

    詳解php的socket通信

    這篇文章通過(guò)案例演示詳細(xì)介紹了php的socket通信,對(duì)每一段代碼進(jìn)行了分析,每一步驟都配有詳細(xì)說(shuō)明,感興趣的的朋友可以參考下
    2015-08-08
  • PHP計(jì)算日期相差天數(shù)實(shí)例分析

    PHP計(jì)算日期相差天數(shù)實(shí)例分析

    這篇文章主要介紹了PHP計(jì)算日期相差天數(shù)的方法,結(jié)合實(shí)例形式分析了PHP日期與時(shí)間操作及換算的相關(guān)技巧,需要的朋友可以參考下
    2016-02-02
  • php中文語(yǔ)義分析實(shí)現(xiàn)方法示例

    php中文語(yǔ)義分析實(shí)現(xiàn)方法示例

    這篇文章主要介紹了php中文語(yǔ)義分析實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了PHP基于BosonNLP擴(kuò)展實(shí)現(xiàn)中文語(yǔ)義分析的具體操作步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-09-09
  • PHP中header和session_start前不能有輸出原因分析

    PHP中header和session_start前不能有輸出原因分析

    在http傳輸文本中,規(guī)定必須 header和content順序必須是:header在前content在后,并且header的格式必須滿(mǎn)足“keyword: value\n”這種格式,大家知道這是為什么嗎?接下來(lái)為您詳細(xì)解答
    2013-01-01
  • php5與php7的區(qū)別點(diǎn)總結(jié)

    php5與php7的區(qū)別點(diǎn)總結(jié)

    在本篇文章里小編給大家整理的是關(guān)于php5與php7的區(qū)別是什么的相關(guān)知識(shí)點(diǎn)內(nèi)容,有需要的朋友們學(xué)習(xí)下。
    2019-10-10
  • 淺談PHP中單引號(hào)和雙引號(hào)到底有啥區(qū)別呢?

    淺談PHP中單引號(hào)和雙引號(hào)到底有啥區(qū)別呢?

    本文向我們簡(jiǎn)單介紹了php中單雙引號(hào)的區(qū)別,以及對(duì)比了下javascript中單引號(hào)和雙引號(hào)的區(qū)別,方便我們更好的理解,非常實(shí)用,推薦給大家
    2015-03-03
  • PHP+MySQL實(shí)現(xiàn)無(wú)極限分類(lèi)欄目的方法

    PHP+MySQL實(shí)現(xiàn)無(wú)極限分類(lèi)欄目的方法

    這篇文章主要介紹了PHP+MySQL實(shí)現(xiàn)無(wú)極限分類(lèi)欄目的方法,涉及php操作數(shù)據(jù)庫(kù)查詢(xún)及結(jié)果集遞歸遍歷的技巧,需要的朋友可以參考下
    2015-12-12
  • 安裝apache2.2.22配置php5.4(具體操作步驟)

    安裝apache2.2.22配置php5.4(具體操作步驟)

    本篇文章是對(duì)安裝apache2.2.22配置php5.4的具體操作步驟進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • kindeditor 加入七牛云上傳的實(shí)例講解

    kindeditor 加入七牛云上傳的實(shí)例講解

    下面小編就為大家?guī)?lái)一篇kindeditor 加入七牛云上傳的實(shí)例講解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11

最新評(píng)論