CakeFest 2024: The Official CakePHP Conference

mcrypt_get_iv_size

(PHP 4 >= 4.0.2, PHP 5, PHP 7 < 7.2.0, PECL mcrypt >= 1.0.0)

mcrypt_get_iv_size返回指定算法/模式组合的初始向量大小

警告

本函数已自 PHP 7.1.0 起废弃并将自 PHP 7.2.0 起移除。强烈建议不要使用本函数。

说明

mcrypt_get_iv_size(string $cipher, string $mode): int

获取由 cipher/mode 参数指定的初始向量大小。

mcrypt_enc_get_iv_size() 更加有用, 因为它使用由 mcrypt_module_open() 返回的资源作为参数。

参数

cipher

MCRYPT_ciphername 常量中的一个,或者是字符串值的算法名称。

mode

MCRYPT_MODE_modename 常量中的一个,或以下字符串中的一个:"ecb","cbc","cfb","ofb","nofb" 和 "stream"。

由于 ECB 模式不使用初始向量,所以会忽略它。 在加密和解密的过程中, 你需要使用相同的初始向量(想象成:开始点)。

返回值

返回初始向量的大小,以字节为单位。 如果发生错误,返回 false。 如果指定的算法/模式不需要初始向量,返回 0。

示例

示例 #1 mcrypt_get_iv_size() 示例

<?php
echo mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB) . "\n";

echo
mcrypt_get_iv_size('des', 'ecb') . "\n";
?>

参见

add a note

User Contributed Notes 1 note

up
-5
Hernanibus
7 years ago
The size of the initialization vector (iv) will be returned in bytes NOT bits, something to keep in mind specially if the iv is passed together appended or prepended with the encrypted data for decryption
To Top