在ECB模式下可以使用AES和IV吗? [英] Is it possible to use AES with an IV in ECB mode?

查看:4176
本文介绍了在ECB模式下可以使用AES和IV吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://php.net/manual/en/function。 mcrypt-encrypt.php ,我在ECB模式下使用AES看到了以下代码,使用AES,

From http://php.net/manual/en/function.mcrypt-encrypt.php, I saw the following codes using AES with an IV in ECB mode,

<?php
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $key = "This is a very secret key";
    $text = "Meet me at 11 o'clock behind the monument.";
    echo strlen($text) . "\n";

    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
    echo strlen($crypttext) . "\n";
?>

但是来自wiki http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation ,它表示ECB不需要IV。
在ECB模式下真的可以使用AES和IV吗?在这种ECB模式下,额外的IV将提供比不使用时更多的安全性。

But from wiki http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation, it says ECB does not need an IV. Is it really possible to use AES with an IV in ECB mode? In this ECB mode, will the additional IV provide a little bit more security comparing to when it is not used?

推荐答案

ECB不执行块之间的链接,所以没有办法使用IV。 mcrypt对所有模块使用相同的APi。因为ECB模块具有定义为

ECB doesn't perform chaining between blocks so there is no way to use IV. mcrypt uses the same APi for all modules. The IV is simply ignored for ECB because the ECB module has following function defined as,

int _has_iv() { return 0; }

这篇关于在ECB模式下可以使用AES和IV吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆