gpt4 book ai didi

php实现aes加密类分享

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 26 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章php实现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加密类分享的文章就讲到这里了,如果你想了解更多关于php实现aes加密类分享的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com