©
本文档使用 PHP中文网手册 发布
下表是 mcrypt 扩展所支持的密码。 所支持的密码的完整列表请参见 mcrypt.h 文件。 在 PHP 中使用 mcrypt-2.2.x 的一个通用规则是你可以使用 MCRYPT_ciphername 来访问密码。 在 libmcrypt-2.4.x 和 libmcrypt-2.5.x 的 API 中,这些常量依然可用, 但是你也可以把密码模式以字符串的形式传入 mcrypt_module_open() 函数 来进行访问。
如果使用 CFB
和 OFB
模式,
必须提供初始向量(IV),
如果使用 CBC
模式,
可以提供一个初始向量。
初始向量必须是唯一的,并且在加密和解密过程中要保持一致。
你可以将初始向量和加密后数据一起存储,
其存储位置可以由一个函数的输出来指定,
例如文件名的 MD5 散列值,
这样你就可以把初始向量和加密后的数据一起传输
(关于本话题的更多信息,请参见 Applied Cryptography by Schneier (ISBN 0-471-11709-9) 9.3 一节)。
[#1] dan at zaph dot com [2015-08-21 12:26:00]
Interpretability:
mcrypt does not support PKCS#7 padding, it uses non-standard and insecure null padding. This means that for interoperability with most other implementations PKCS#7 padding will have to be added prior to encryption and/or removed after decryption. This is a major source of interoperability issues.
When interoperating with AES the mcrypt algorithm must be specified as MCRYPT_RIJNDAEL_128 since AES only supports a block size of 128-bits. There is often confusion that this specifies the key size which it does not.
[#2] stanislav dot eckert at vizson dot de [2015-06-01 17:33:51]
The latest patents for the IDEA algorithm have expired in 2012 and the cipher is now patent-free and free to use.
[#3] Rob [2013-12-31 15:28:11]
These constants can in fact be used as input to the function mcrypt_module_open() because mcrypt.php contains defines that map these constants to the appropriate string values obtained from mcrypt_list_algorithms().
[#4] Mark [2012-10-29 14:13:49]
Note, these are not the names you use in the function mcrypt_module_open to specify the algorithm.
Use mcrypt_list_algorithms to get the right names to stick in there
[#5] robin [2010-12-17 09:41:57]
The MCRYPT_TWOFISH constant when defined by mcrypt version 2.4.x and later is the 256 bit version of Twofish; it uses a 1-32 byte key, a 16 byte IV, and outputs 16 byte blocks in CBC mode.