PHP 中的 AES-256 加密
我需要一个 PHP 函数 AES256_encode($dataToEcrypt)
将 $data
加密为 AES-256,另一个 AES256_decode($encryptedData)
执行此操作相反。有谁知道这个函数应该有什么代码?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
mcrypt 模块
查看来自 AES-Rijndael 示例://www.php.net/manual/en/function.mcrypt-encrypt.php" rel="noreferrer">此处
这是 解密函数
Look at the mcrypt module
AES-Rijndael example taken from here
This is the decrypt function
加密和编码之间存在差异。
您真的需要 AES-256 吗?与 AES-128 相比,AES-256 的安全性并不那么重要;你更有可能在协议层搞砸而不是被黑客攻击,因为你使用的是 128 位分组密码而不是 256 位分组密码。
重要 - 使用库
快速而肮脏的 AES-256 实现
如果您有兴趣构建自己的不是为了在生产中部署它而是为了为了你的缘故根据我自己的教育,我提供了一个示例 AES256
用法
首先,生成两个密钥(是的,其中两个)并以某种方式存储它们。
然后加密/解密消息:
如果您没有
random_bytes()
,请获取 random_compat< /a>.There is a difference between encrypting and encoding.
Do you really need AES-256? The security of AES-256 versus AES-128 isn't that significant; you're more likely to screw up at the protocol layer than get hacked because you used a 128-bit block cipher instead of a 256-bit block cipher.
Important - Use A Library
A Quick and Dirty AES-256 Implementation
If you're interested in building your own not for the sake of deploying it in production but rather for the sake of your own education, I've included a sample AES256
Usage
First, generate two keys (yes, two of them) and store them somehow.
Then to encrypt/decrypt messages:
If you don't have
random_bytes()
, get random_compat.MCRYPT_RIJNDAEL_256 不等同于 AES_256。
使 RIJNDAEL 从 AES 解密的方法是使用 MCRYPT_RIJNDAEL_128 并在加密
AES-256 之前填充要加密的字符串,其 BlockSize=128bit 和 KeySize=256bit
Rijndael-256 的 BlockSize=256bit 和 KeySize=256bit
只是 AES/Rijndael 128bit 是相同的。
Rijndael-192 和 Rijndael-256 与 AES-192 和 AES-256 不同(块大小和轮数不同)。
MCRYPT_RIJNDAEL_256 is not equivalent to AES_256.
The way to make RIJNDAEL be decrypted from AES is to use MCRYPT_RIJNDAEL_128 and padd the string to encrypt before encrypting
AES-256 has BlockSize=128bit and KeySize=256bit
Rijndael-256 has BlockSize=256bit and KeySize=256bit
Just AES/Rijndael 128bit are identical.
Rijndael-192 and Rijndael-256 are not identical to AES-192 and AES-256 (block sizes and number of rounds differ).