当前位置:网站首页>Implementing AES encryption and decryption with PHP
Implementing AES encryption and decryption with PHP
2022-04-21 07:55:00 【Mars Murong】
PHP Realization AES Encryption and decryption
class Aes
{
/**
* var string $method Encryption and decryption methods , It can be done by openssl_get_cipher_methods() get
*/
protected $method;
/**
* var string $secret_key Encryption and decryption key
*/
protected $secret_key;
/**
* var string $iv Decrypted vector , Some methods need to be set, such as CBC
*/
protected $iv;
/**
* var string $options ( I don't know how to explain , Currently set to 0 No problem )
*/
protected $options;
/**
* Constructors
*
* @param string $key secret key
* @param string $method encryption
* @param string $iv iv vector
* @param mixed $options
*
*/
public function __construct($key, $method = 'AES-128-ECB', $iv = '', $options = 0)
{
// key It must be set
$this->secret_key = isset($key) ? $key : 'morefun';
$this->method = $method;
$this->iv = $iv;
$this->options = $options;
}
/**
* Encryption method , Encrypt data , Return encrypted data
*
* @param string $data Data to encrypt
*
* @return string
*
*/
public function encrypt($data)
{
return openssl_encrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
}
/**
* Decryption method , Decrypt data , Return decrypted data
*
* @param string $data Data to decrypt
*
* @return string
*
*/
public function decrypt($data)
{
return openssl_decrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
}
}
版权声明
本文为[Mars Murong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210629261857.html
边栏推荐
猜你喜欢

Axure产品原型工具使用笔记

leetcode题目--120.三角形最小长度和,简单dp

Shortcut keys for batch modification of variable name and batch replacement code in idea

Flutter 环境搭建等基础

Hackmyvm integrated target | driftingblues-9 (end)

343. 求分解整数的乘积最大化Integer Break

Bluetooth profile specification (AVRCP chapter) 5.1 connection and release of vctp

【图像融合】基于curvelet变换实现图像融合(评价指标)含Matlab源码

Record the problems and solutions encountered in using fastjson message converter

Steps for umlet beginners
随机推荐
Bluetooth Profile Specification之(AVRCP篇)5.1AVCTP的连接和释放
asp.net js 实现动态添加文件上传
Command-Line
MySQL5.7安装操作手册(Centos7)
Introduction to QT 5.12 actual combat
pycharm 最新导入PIL库的方法
虚拟机 主机 ping ssh 校园网 桥接 NET
Leetcode 704 · binary search
云原生KubeSphere实战多租户系统实战
oracle 管理之《sql命令》
C语言指针进阶(1.一阶与二阶指针)
Environment Variables
URL Parsing
Postgre(pg)-SQL脚本记录
Introduction to btstack 1.0 of Bluetooth open source protocol stack
PHP去除字符串开头或末尾逗号
Hackmyvm综合靶机 | Driftingblues-9(完结)
2022-04-20:小团去参加军训,军训快要结束了, 长官想要把大家一排n个人分成m组,然后让每组分别去参加阅兵仪式, 只能选择相邻的人一组,不能随意改变队伍中人的位置, 阅兵仪式上会进行打分,其中
C# asp. Net calling Baidu character recognition interface
Flutter environment construction and other foundations