欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實(shí)現(xiàn)aes加密類分享

 更新時(shí)間:2014年02月16日 15:53:39   作者:  
這篇文章主要介紹了php實(shí)現(xiàn)的aes加密類,代碼中有使用方法,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

<?php

class AESMcrypt {

 public $iv = null;
 public $key = null;
 public $bit = 128;
 private $cipher;

 public function __construct($bit, $key, $iv, $mode) {
  if(empty($bit) || empty($key) || empty($iv) || empty($mode))
  return NULL;

  $this->bit = $bit;
  $this->key = $key;
  $this->iv = $iv;
  $this->mode = $mode;

  switch($this->bit) {
   case 192:$this->cipher = MCRYPT_RIJNDAEL_192; break;
   case 256:$this->cipher = MCRYPT_RIJNDAEL_256; break;
   default: $this->cipher = MCRYPT_RIJNDAEL_128;
  }

  switch($this->mode) {
   case 'ecb':$this->mode = MCRYPT_MODE_ECB; break;
   case 'cfb':$this->mode = MCRYPT_MODE_CFB; break;
   case 'ofb':$this->mode = MCRYPT_MODE_OFB; break;
   case 'nofb':$this->mode = MCRYPT_MODE_NOFB; break;
   default: $this->mode = MCRYPT_MODE_CBC;
  }
 }

 public function encrypt($data) {
  $data = base64_encode(mcrypt_encrypt( $this->cipher, $this->key, $data, $this->mode, $this->iv));
  return $data;
 }

 public function decrypt($data) {
  $data = mcrypt_decrypt( $this->cipher, $this->key, base64_decode($data), $this->mode, $this->iv);
  $data = rtrim(rtrim($data), "\x00..\x1F");
  return $data;
 }

}

//使用方法
$aes = new AESMcrypt($bit = 128, $key = 'abcdef1234567890', $iv = '0987654321fedcba', $mode = 'cbc');
$c = $aes->encrypt('haowei.me');
var_dump($aes->decrypt($c));

相關(guān)文章

  • php 實(shí)現(xiàn)收藏功能的示例代碼

    php 實(shí)現(xiàn)收藏功能的示例代碼

    本篇文章主要介紹了php 實(shí)現(xiàn)收藏功能的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • thinkPHP+PHPExcel實(shí)現(xiàn)讀取文件日期的方法(含時(shí)分秒)

    thinkPHP+PHPExcel實(shí)現(xiàn)讀取文件日期的方法(含時(shí)分秒)

    這篇文章主要介紹了thinkPHP+PHPExcel實(shí)現(xiàn)讀取文件日期的方法,可實(shí)現(xiàn)針對時(shí)分秒的形式進(jìn)行讀取的功能,涉及PHPExcel中ExcelToPHP函數(shù)的相關(guān)使用方法,需要的朋友可以參考下
    2016-07-07
  • Laravel中為什么不使用blpop取隊(duì)列詳析

    Laravel中為什么不使用blpop取隊(duì)列詳析

    這篇文章主要給大家介紹了關(guān)于Laravel中為什么不使用blpop取隊(duì)列的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-08-08
  • php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息

    php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息

    這篇文章主要給大家介紹了關(guān)于php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-03-03
  • ThinkPHP3.1新特性之多數(shù)據(jù)庫操作更加完善

    ThinkPHP3.1新特性之多數(shù)據(jù)庫操作更加完善

    對于早期版本的ThinkPHP來說,切換數(shù)據(jù)庫需要使用高級模型,而現(xiàn)在的3.1版本則可以更加輕松的解決了。這篇文章主要介紹了ThinkPHP3.1對多數(shù)據(jù)庫操作,需要的朋友可以參考下
    2014-06-06
  • PHP實(shí)現(xiàn)無限分類的實(shí)現(xiàn)方法

    PHP實(shí)現(xiàn)無限分類的實(shí)現(xiàn)方法

    無限級分類是一種設(shè)計(jì)技巧,在開發(fā)中經(jīng)常使用,本篇文章主要介紹PHP實(shí)現(xiàn)無限分類的實(shí)現(xiàn)方法,有需要的可以了解一下。
    2016-11-11
  • function.inc.php超越php

    function.inc.php超越php

    function.inc.php超越php...
    2006-12-12
  • Laravel中Kafka的使用詳解

    Laravel中Kafka的使用詳解

    這篇文章主要介紹了Laravel中Kafka的使用詳解,kafka是一個(gè)分布式消息隊(duì)列,具有高性能、持久化、多副本備份、橫向擴(kuò)展能力,有對于消息隊(duì)列感興趣的同學(xué)可以參考下
    2021-03-03
  • thinkPHP中session()方法用法詳解

    thinkPHP中session()方法用法詳解

    這篇文章主要介紹了thinkPHP中session()方法用法,結(jié)合實(shí)例形式分析了thinkPHP中session方法的功能、參數(shù)、具體使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-12-12
  • PHP date()函數(shù)警告: It is not safe to rely on the system解決方法

    PHP date()函數(shù)警告: It is not safe to rely on the system解決方法

    這篇文章主要介紹了PHP date()函數(shù)警告: It is not safe to rely on the system解決方法,其實(shí)就是時(shí)區(qū)設(shè)置不正確造成的,本文提供了兩種方法來解決這個(gè)問題,需要的朋友可以參考下
    2014-08-08

最新評論