PHP 有一个使用 php 的 AES 方法加密和解密字符串的内置扩展。 函数 openssl_encrypt() 用于加密字符串,openssl_decrypt() 用于解密字符串。 在 P
PHP 有一个使用 php 的 AES
方法加密和解密字符串的内置扩展。
函数 openssl_encrypt()
用于加密字符串,openssl_decrypt()
用于解密字符串。
openssl_encrypt()
和 openssl_decrypt()
采用一组强制和可选参数,有关参数的信息如下表所示:
范围 | 描述 |
---|---|
data |
纯文本/字符串 |
cipher_alGo |
密码方法,在我们的例子中,AES |
passphrase |
如果密码短语短于限制,则会用空字符静默填充,如果长则截断。 |
options |
标志的按位分离。OPENSSL_RAW_DATA 和 OPENSSL_ZERO_PADDING 。 |
iv |
初始化向量,非空 |
tag |
身份验证标签 CGM 或 CCM |
aad |
额外的身份验证数据。 |
tag_length |
身份验证标签的长度在 4 到 16 之间 |
openssl_encrypt()
采用上述所有参数,并在使用 openssl_decrypt()
时排除 aad
和 tag_length
。
<?php
//Encryption
$original_string = "Hello! This is jiyik.com"; // Plain text/String
$cipher_algo = "AES-128-CTR"; //The cipher method, in our case, AES
$iv_length = openssl_cipher_iv_length($cipher_algo); //The length of the initialization vector
$option = 0; //Bitwise disjunction of flags
$encrypt_iv = '8746376827619797'; //Initialization vector, non-null
$encrypt_key = "jiyik!"; // The encryption key
// Use openssl_encrypt() encrypt the given string
$encrypted_string = openssl_encrypt($original_string, $cipher_algo,
$encrypt_key, $option, $encrypt_iv);
//Decryption
$decrypt_iv = '8746376827619797'; //Initialization vector, non-null
$decrypt_key = "jiyik!"; // The encryption key
// Use openssl_decrypt() to decrypt the string
$decrypted_string=openssl_decrypt ($encrypted_string, $cipher_algo,
$decrypt_key, $option, $decrypt_iv);
//Display Strings
echo "The Original String is: <br>" . $original_string. "<br><br>" ;
echo "The Encrypted String is: <br>" . $encrypted_string . "<br><br>";
echo "The Decrypted String is: <br>" . $decrypted_string;
?>
上面的代码首先使用 AES
方法对字符串进行加密,然后对其进行解密。
输出:
The Original String is:
Hello! This is jiyik.com
The Encrypted String is:
JF1iHtW4I9qK8q9OwCL9Yh1ejtZofci5
The Decrypted String is:
Hello! This is jiyik.com
AES 根据方法和位数具有不同的 cipher_algorithams
,例如 aes-128-cbc
、aes-192-cfb
或 aes-256-cbc
。
此处查看 AES 加密和其他方法的所有选项。
--结束END--
本文标题: PHP AES 加密解密
本文链接: https://www.lsjlt.com/news/569164.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
一口价域名售卖能注册吗?域名是网站的标识,简短且易于记忆,为在线用户提供了访问我们网站的简单路径。一口价是在域名交易中一种常见的模式,而这种通常是针对已经被注册的域名转售给其他人的一种方式。
一口价域名买卖的过程通常包括以下几个步骤:
1.寻找:买家需要在域名售卖平台上找到心仪的一口价域名。平台通常会为每个可售的域名提供详细的描述,包括价格、年龄、流
443px" 443px) https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294.jpg https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294-768x413.jpg 域名售卖 域名一口价售卖 游戏音频 赋值/切片 框架优势 评估指南 项目规模
0