Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mcrypt初始化模块的时间过长_Php_Mcrypt - Fatal编程技术网

Php mcrypt初始化模块的时间过长

Php mcrypt初始化模块的时间过长,php,mcrypt,Php,Mcrypt,我有一个类,它有以下结构 final class mydecoder { private $td; public function __construct($key){ /* Open the cipher */ $this->td = mcrypt_module_open(MCRYPT_BLOWFISH, '', 'ecb', ''); /* Create the IV and determine the keysize l

我有一个类,它有以下结构

final class mydecoder {
    private $td;
    public function __construct($key){
        /* Open the cipher */
        $this->td = mcrypt_module_open(MCRYPT_BLOWFISH, '', 'ecb', '');
        /* Create the IV and determine the keysize length, use MCRYPT_RAND
        * on Windows instead */
        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_DEV_RANDOM);
        $ks = mcrypt_enc_get_key_size($this->td);
        /* Create key */
        $key = substr(md5($key), 0, $ks);
        /* Intialize encryption */
        mcrypt_generic_init($this->td, $key, $iv);
    }
}
当我这样称呼它时:

$encoder = new myfish('mykey1');
$encoder = new myfish('mykey2');
我有以下问题

第一次翻页

construct #1 execution time: 5s
construct #2 execution time: 0s
按F5

construct #1 execution time: 0s
construct #2 execution time: 14s
construct #1 execution time: 5s
construct #2 execution time: 14s
按F5

construct #1 execution time: 0s
construct #2 execution time: 14s
construct #1 execution time: 5s
construct #2 execution time: 14s
捣碎F5 3次(排队)


看起来像是在排队?它是如何工作的?也许我没有正确地使用它?我对加密技术没有太多经验,因为我以前从未使用过:)

问题是由初始化向量(IV)生成器引起的,即这一行:

$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($this->td), MCRYPT_DEV_RANDOM);
如果您使用
MCRYPT\u DEV\u RANDOM
模式,PHP将等到有足够的熵来保证安全


但是,如果您将模式更改为
MCRYPT\u DEV\u URANDOM
(安全性会降低),但如果熵太低,它不会等待,从而提高速度。

因此,基本上,使用
MCRYPT\u DEV\u RANDOM
会造成延迟,因此随机数彼此之间的距离“更远”?我为您找到了一个更好的解释: