当前位置:网站首页>Aes-128-cbc-pkcs7padding encrypted PHP instance
Aes-128-cbc-pkcs7padding encrypted PHP instance
2022-06-29 12:50:00 【owenzhang24】
The environment of this article PHP8.1,Mysql5.7
If you don't understand, you can comment or contact my email :[email protected]
The copyright belongs to OwenZhang all . Commercial reprint please contact OwenZhang authorized , Non-commercial reprint please indicate the source .
Probably
AES-128-CBC-Pkcs7Padding encryption PHP example :
(https://www.mklab.cn/utils/aes)
code base64, Pattern cbc, fill Pkcs7Padding, digit 128 position ,
Input format base64, Output format string, Character set utf-8,
secret key T3lUf3t4ddHzSx8U, Offset cdccB3uiWDu7mcxw
( for example 17350886066 After encryption +eupvMFtSc0E7veMi+XCgQ==)
(https://www.lddgo.net/encrypt/aes)

AES Introduce
1.AES brief introduction :
AES Advanced encryption standard (Advanced Encryption Standard), Is the U.S. NIST stay 2001 Published in , To replace DES Known as a widely used standard .AES Is a symmetric block cipher algorithm .
2.AES Packet length and key length :
AES The plaintext packet length of is 128 position (16 byte ), The key length can be 128 position (16 byte )、192 position (24 byte )、256 position (32 byte ), Depending on the length of the key ,AES It is divided into AES-128、AES-192、AES-256 Three .
AES-PHP Service code
Code block Introduction
openssl_encrypt($data, $method, $password, $options, $iv)
- Parameter description :
- $data Encrypt plaintext
- $method Encryption method : DES-ECB
DES-CBC
DES-CTR
DES-OFB
DES-CFB
$passwd Encryption key [ password ]
$options Data format options ( Optional )【 Option has :】 0
OPENSSL_RAW_DATA=1
OPENSSL_ZERO_PADDING=2
OPENSSL_NO_PADDING=3
- $iv Secret initialization vector ( Optional )
If method by DES-ECB, be iv No need to fill in
Specific code
<?phpnamespace app\service;class AesService{ public static ?AesService $_instance = null; /* secret key ,22 Characters */ protected string $key = 'T3lUf3t4ddHzSx8U'; /* vector ,8 Or 10 Characters */ protected string $iv = 'cdccB3uiWDu7mcxw'; /** * @return AesService|mixed */ public static function instance(): ?AesService { if (!static::$_instance) static::$_instance = new self(); return static::$_instance; } public function setkey(string $key): static { $this->key = $key; return $this; } public function getkey(): string { return $this->key; } public function getiv(): string { return $this->iv; } /** * encryption * AES/CBC/PKCS7Padding * AES encryption :(https://www.mklab.cn/utils/aes) * code base64, Pattern CBC, fill Pkcs7Padding, digit 128 position , Input format base64, Output format string, * Character set utf-8, secret key T3lUf3t4ddHzSx8U, Offset cdccB3uiWDu7mcxw * ( for example 17350886066 After encryption +eupvMFtSc0E7veMi+XCgQ==) * (https://www.lddgo.net/encrypt/aes) * * @param boolean $status Is it encrypted * * @return string Processed data */ public function encrypt($data, bool $status = true): string { if (is_array($data)) $data = json_encode($data); $key = $this->getkey(); $iv = $this->getiv(); if ($status) return base64_encode(openssl_encrypt($data, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv)); return $data; } /** * Decrypt * * @return string The encrypted string is not complete and will return an empty string value */ public function decrypt($data, bool $status = true): string { $key = $this->getkey(); $iv = $this->getiv(); if ($status) return openssl_decrypt(base64_decode($data), 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv); return $data; }}AES- Calling code
AES encryption
const API_AES_KEY = 'T3lUf3t4ddHzSx8U'; $mobileAesEncrypt = AesService::instance()->setkey(API_AES_KEY)->encrypt('17350886066');
AES Decrypt
const API_AES_KEY = 'T3lUf3t4ddHzSx8U'; $mobileAesDecrypt = AesService::instance()->setkey(API_AES_KEY)->decrypt('+eupvMFtSc0E7veMi+XCgQ==');
Buy me a cup of coffee :)
Think it will help you , Just give me a reward , thank you !
Wechat appreciation code link , Click the jump :
边栏推荐
- 【JUC系列】同步工具类之ThreadLocal
- 推荐模型复现(四):多任务模型ESMM、MMOE
- LR、CR纽扣电池对照表
- Gbase8s database select has order by Clause 2
- Gbase8s database select has order by Clause 4
- How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native architecture vs traditional IT architecture
- 深入理解 volatile 关键字
- How to fix ORA-01017:用户名/口令无效 登录拒绝
- Huffman coding
- 《高难度谈话》突破谈话瓶颈,实现完美沟通
猜你喜欢

高校如何基于云原生构建面向未来的智慧校园?全栈云原生架构VS传统IT架构

Proteus Software beginner notes
![[comprehensive case] credit card virtual transaction identification](/img/85/9915ab9a6100a022dfa1c0050d554f.png)
[comprehensive case] credit card virtual transaction identification

墨菲安全入选中关村科学城24个重点项目签约

C#通过中序遍历对二叉树进行线索化

ERP Kingdee for preparing BOM
![[leetcode] 14. Longest public prefix](/img/3b/3388ce8382ad5caaaf0a42488da2f9.png)
[leetcode] 14. Longest public prefix

倍福TwinCAT配置、调试第三方伺服详细讲解--以汇川IS620N为例子

MATLAB求极限

Recurrence of recommended models (IV): multi task models esmm and MMOE
随机推荐
C#通过中序遍历对二叉树进行线索化
Kyligence Zen, an intelligent indicator driven management and decision-making platform, is newly launched and is in limited internal testing
Newton inequality
测试--自动化测试:关于unittest框架
qt json
AES-128-CBC-Pkcs7Padding加密PHP实例
File contained log poisoning (user agent)
推荐模型复现(二):精排模型DeepFM、DIN
ERP Kingdee for preparing BOM
如何計算win/tai/loss in paired t-test
推荐模型复现(三):召回模型YoutubeDNN、DSSM
Interview shock 61: tell me about MySQL transaction isolation level?
Paper reproduction - ac-fpn:attention-guided context feature pyramid network for object detection
Difficult conversation breaks through the bottleneck of conversation and achieves perfect communication
LR、CR纽扣电池对照表
MFC dialog program core -isdialogmessage function -msg message structure -getmessage function -dispatchmessage function
oracle 19c : change the user sys/system username pasword under Linux
C # indexe l'arbre binaire en traversant l'ordre moyen
倍福TwinCAT3 的OPC_UA通信测试案例
[环境配置]PWC-Net