略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 预定义常量

2024-03-29

预定义常量

下列常量由此扩展定义,且仅在此扩展编译入 PHP 或在运行时动态载入时可用。

Mcrypt 支持以下四种分组密码模式:CBCOFBCFBECB。 如果使用 libmcrypt-2.4.x 或更高版本链接, 还可以支持 nOFB 分组模式 和 STREAM 模式。 下列是所支持的加密模式以及其对应的预定义常量。 完整的参考见:Applied Cryptography by Schneier (ISBN 0-471-11709-9)。

  • MCRYPT_MODE_ECB (electronic codebook) 是一种分组加密模式,但是它无法适用于大部分场景, 所以不建议使用这种模式进行分组加密。
  • MCRYPT_MODE_CBC (cipher block chaining) 也是一种分组加密方式, 相对 ECB 模式,它更加安全。
  • MCRYPT_MODE_CFB (8 比特模式的 cipher feedback) 是一种流式加密模式。 相对于 CFB 而言, 推荐使用 NCFB 模式。
  • MCRYPT_MODE_OFB (output feedback, in 8bit) 和 CFB 类似, 也是一种流式加密模式,它可以用在无法容忍加密错误传播的应用中。 推荐使用 NOFB 模式,而不是 OFB 模式。
  • MCRYPT_MODE_NOFB (output feedback, in nbit) 和 OFB 类似,但是更加安全, 因为它可以按照算法指定的分组大小来对数据进行加密。
  • MCRYPT_MODE_STREAM 是一种扩展模式, 它包含了诸如 "WAKE""RC4" 的流加密算法。

Mcrypt 还支持一些尚未预定义常量的加密模式。 可以通过传入一个字符串来使用使用未预定义常量的加密模式。

  • "ctr" (counter mode) 是一种流式加密模式。
  • "ncfb" (cipher feedback, in n-bit mode),类似于 CFB 模式, 但是它会对于算法设定的整块数据进行操作。

其他模式以及随机设备常量:

MCRYPT_ENCRYPT (integer)
MCRYPT_DECRYPT (integer)
MCRYPT_DEV_RANDOM (integer)
MCRYPT_DEV_URANDOM (integer)
MCRYPT_RAND (integer)
add a noteadd a note

User Contributed Notes 2 notes

up
7
gordon at vixo dot com
9 years ago
These constants don't cover all the possible options.

There are two constants:
MCRYPT_MODE_OFB
MCRYPT_MODE_NOFB

These relate to using OFB mode in 8-bit feedback mode and using the same feedback length as the key

There is one constant
MCRYPT_MODE_CFB which uses 8-bit feedback mode

There ought to be a constant
MCRYPT_MODE_NCFB which uses the same feedback length as the key.

In fact you can just use the option 'ncfb' in mycrypt
up
-16
Andrey Andreev
8 years ago
You can just use strings instead of the constants ... they are useless and lacking for other modes that are fully supported. Here's a list:

cbc
ecb
ofb
nofb
cfb
ncfb
ctr
stream

官方地址:https://www.php.net/manual/en/mcrypt.constants.php

冷却塔厂家 广告
-- 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3