php實(shí)現(xiàn)aes加密類分享
<?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));
- php中AES加密解密的例子小結(jié)
- php寫的AES加密解密類分享
- PHP的AES加密算法完整實(shí)例
- PHP實(shí)現(xiàn)的簡單AES加密解密算法實(shí)例
- PHP實(shí)現(xiàn)AES256加密算法實(shí)例
- JS實(shí)現(xiàn)AES加密并與PHP互通的方法分析
- 標(biāo)準(zhǔn)PHP的AES加密算法類
- PHP對稱加密算法(DES/AES)類的實(shí)現(xiàn)代碼
- PHP7.1實(shí)現(xiàn)的AES與RSA加密操作示例
- php實(shí)現(xiàn)的AES加密類定義與用法示例
- PHP實(shí)現(xiàn)的AES加密、解密封裝類與用法示例
相關(guān)文章
thinkPHP+PHPExcel實(shí)現(xiàn)讀取文件日期的方法(含時(shí)分秒)
這篇文章主要介紹了thinkPHP+PHPExcel實(shí)現(xiàn)讀取文件日期的方法,可實(shí)現(xiàn)針對時(shí)分秒的形式進(jìn)行讀取的功能,涉及PHPExcel中ExcelToPHP函數(shù)的相關(guān)使用方法,需要的朋友可以參考下2016-07-07php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息
這篇文章主要給大家介紹了關(guān)于php+ffmpeg如何獲取視頻縮略圖、視頻分辨率等相關(guān)信息的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-03-03ThinkPHP3.1新特性之多數(shù)據(jù)庫操作更加完善
對于早期版本的ThinkPHP來說,切換數(shù)據(jù)庫需要使用高級模型,而現(xiàn)在的3.1版本則可以更加輕松的解決了。這篇文章主要介紹了ThinkPHP3.1對多數(shù)據(jù)庫操作,需要的朋友可以參考下2014-06-06PHP實(shí)現(xiàn)無限分類的實(shí)現(xiàn)方法
無限級分類是一種設(shè)計(jì)技巧,在開發(fā)中經(jīng)常使用,本篇文章主要介紹PHP實(shí)現(xiàn)無限分類的實(shí)現(xiàn)方法,有需要的可以了解一下。2016-11-11PHP 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