分类分类
更新时间:2026-04-09 12:48:28作者:网络
这篇文章主要介绍了php实现的aes加密类,代码中有使用方法,需要的朋友可以参考下
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));
相关
呱呱AI英语(儿童英语启蒙平台)学习办公334.6 MBv1.3.32026-04-09
下载附近先遇2026下载社交通讯86.0 MBv1.1.412026-04-09
下载变种人吃了我的胡萝卜解锁关卡(冒险童话游戏)趣味娱乐1.20 GBv1.032026-04-09
下载重返战场:特战精英2026下载趣味娱乐99.0 MBv4.12026-04-09
下载手机计算器免费(多功能计算工具)生活服务54.0 MBv1.0.82026-04-09
下载风筝飞呀最新手机版社交通讯64.2 MBv1.1.92026-04-09
下载万用智能点击器(自动化点击工具)生活服务50.7 MBv1.0.02026-04-09
下载天气精准预警(天气查询应用)生活服务46.1 MBv1.00.032026-04-09
下载汽果免费音乐2026最新版本影音播放72.5 MBv1.0.22026-04-09
下载万年吉日日历(黄历天气查询)生活服务40.9 MBv1.0.02026-04-09
下载次元锚2026最新版本社交通讯46.2 MBv1.0.12026-04-09
下载生存战争虫虫助手(沙盒生存战)休闲益智45.0 MBvAPI1.9.0.22026-04-09
下载










