分类分类
更新时间:2026-08-08 12:21:20作者:网络
这篇文章主要介绍了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));
相关
文字密室逃脱手机版冒险游戏255.16 MBv1.62026-08-07
下载苏丹的游戏手机版角色扮演1.02Gv1.0.62026-08-07
下载超市大亨3D手游经营养成253.14 Mv10.252026-08-07
下载你只能推搡动作射击44.62 Mv1.102026-08-07
下载仙逆本尊手游角色扮演298.41 Mv0.0.42026-08-07
下载天使帝国4手机版角色扮演837.88 Mv1.02026-08-07
下载丹墨三国弈手机版策略游戏2.14Gv1.0.02026-08-07
下载CM语音App社交通讯95.16 Mv8.16.02026-08-07
下载光氪灵动app实用工具7.6 Mv1.2.12026-08-07
下载逃出沙盒世界游戏角色扮演247.76 Mv1.0.12026-08-07
下载花选app社交通讯86.6 Mv1.4.4.02026-08-07
下载全域突击动作射击533.41 Mv1.2.32026-08-07
下载










