mcrypt_generic 与 mcrypt_crypt
有谁知道 PHP 加密时 mcrypt_generic 和 mcrypt_encrypt 之间的区别?
Does anyone know the difference between mcrypt_generic and mcrypt_encrypt when it comes to encryption in PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mcrypt_encrypt()
结合了多种方法的功能,而mcrypt_generic()
必须在其他mcrypt_*
调用的特定序列中调用。如果您需要较低级别 API 的灵活性,则可以使用mcrypt_generic()
,而mcrypt_encrypt()
则充当较高级别的实用程序。PHP 文档中的这个示例很好地比较了两种 API 方法。它指的是
mcrypt_ecb()
,但出于比较的目的,您可以认为它与mcrypt_encrypt()
类似。来自 http://us.php.net/manual/en/mcrypt.examples。 php
或者:
mcrypt_encrypt()
combines the functionality of several methods, whereasmcrypt_generic()
must be called within a certain sequence of othermcrypt_*
calls. You would usemcrypt_generic()
if you needed the flexibility of the lower-level API, whereasmcrypt_encrypt()
acts as a higher-level utility.This example in the PHP documentation shows a good comparison between the two API approaches. It refers to
mcrypt_ecb()
, but for the purposes of this comparison you can consider it to be similar tomcrypt_encrypt()
.From http://us.php.net/manual/en/mcrypt.examples.php
Or:
http://php.net/manual/en/function.mcrypt-generic。 php
http://php.net/manual/en/function .mcrypt-encrypt.php
这些函数自 PHP 7.1.0 起已弃用。强烈建议不要依赖这些函数。
如今,最好的选择显然是:
http://php.net/manual/ en/function.password-hash.php
http://php .net/manual/en/function.password-verify.php
http://php.net/manual/en/function.mcrypt-generic.php
http://php.net/manual/en/function.mcrypt-encrypt.php
These functions has been DEPRECATED as of PHP 7.1.0. Relying on these function is highly discouraged.
Nowadays, the best option apparently is:
http://php.net/manual/en/function.password-hash.php
http://php.net/manual/en/function.password-verify.php